2017-11-15 7 views
0

zuerst bekommen ich ein Beispiel, was istprüft Punkt innerhalb eines Polygons ist, das ist eine CSV-Datei

poly = [190, 50, 500, 310] 
bbPath = mplPath.Path(np.array([[poly[0], poly[1]], 
       [poly[1], poly[2]], 
       [poly[2], poly[3]], 
       [poly[3], poly[0]]])) 

bbPath.contains_point((200, 100)) 

die coordinate.csv Datei zwei Spalte, erste Spalte ‚Länge 190 50 500 310‘, zweite Spalte ‚nördliche Breite 50 500 310 190‘

was habe ich versucht

with open('coordinate.csv') as csvfile: 
readCSV = csv.reader(csvfile, delimiter=',') 
for row in readCSV: 
    print(row) 

ist, ich weiß nicht, wie cSV-Daten in den Weg zu importieren und überprüfen, ob Punkt innerhalb eines Polygons ist

+0

Können Sie Ihre Datei 'coordinate.csv' oder zumindest einen Teil davon bitte teilen. –

+0

Die Datei "coordinate.csv" hat zwei Spalten, die erste Spalte "Länge 190 50 500 310", die zweite Spalte "Breite 50 500 310 190". – Trux

Antwort

0

Sie müssen einige einfache Manipulationen an jede Zeile Ihrer CSV-Datei auszuführen:

from matplotlib import path as mplPath 
import numpy as np 

with open('coordinate.csv') as csvfile: 
    readCSV = csv.reader(csvfile, delimiter=',') 
    for row in readCSV: 
     lon_list = row[0].split(' ') #split first column into words 
     lat_list = row[1].split(' ') #split second column into words 
     lonlat_zip = zip(lon_list[1:], lat_list[1:]) #zip lists together (skipping first word) 
     lonlat_list = list(lonlat_zip) #create list 
     lonlat_arr = np.array(lonlat_list) #create array 
     bbPath = mplPath.Path(lonlat_arr) #create path 
     result = bbPath.contains_point((200, 100)) 
     print(result) 

ich den Prozess gebrochen habe in kleine Schritte, die Sie zusammen ziehen können. Offensichtlich, wenn die CSV-Datei nicht genau wie beschrieben ist, müssen Sie dies entsprechend ändern.

Verwandte Themen