7 | | |
8 | | |
9 | | |
10 | | import sys |
11 | | import os |
12 | | import shutil |
13 | | from osgeo import ogr, osr |
14 | | |
15 | | def get_location(feature): |
16 | | geometry = feature.GetGeometryRef() |
17 | | x = geometry.GetX() #### Causes Crash |
18 | | y = geometry.GetY() |
19 | | return x,y |
20 | | |
21 | | ### my workaround ... to get it to work |
22 | | ##def get_location(feature): |
23 | | ## s = feature.ExportToJson() |
24 | | ## c = s[s.find('[')+1 : s.find(']')].split(',') |
25 | | ## x,y = float(c[0]),float(c[1]) |
26 | | ## return x,y |
27 | | |
28 | | # read input |
29 | | inputshp = 'IOW_Fire_Hydrants.shp' |
30 | | datasource = ogr.GetDriverByName('ESRI Shapefile').Open(inputshp) |
31 | | if datasource is None: |
32 | | print 'Could not open ' + inputshp |
33 | | sys.exit(-1) |
34 | | inlayer = datasource.GetLayer() |
35 | | get_location(inlayer.GetFeature(1)) |