Monday 25 December 2017

python - Convert shapely polygon coordinates


I am trying to work with a shapefile using shapely, fiona and python. The original coordinate system is in latitude and longitude that I am trying to convert to state plane system. So I want an updated shapefile with coordinates as statePlane. I converted the json object:


fc = fiona.open("sample.shp")   

geoJsonObj = shapefile_record['geometry']
array_coordinates = np.array(geoJsonObj['coordinates'])
array_newCoordinates = copy.deepcopy(array_coordinates)
for counter in range(0,len(array_coordinates[0])):
long,lat = p1(array_coordinates[0][counter][0],array_coordinates[0][counter][1])
#where p1 is a function to do the conversion
array_newCoordinates[0][counter][0] = long
array_newCoordinates[0][counter][1] = lat

geoJsonObj['coordinates'] = array_newCoordinates.tolist()


when i check the coordinates, i get state plane coordinates according to the transformation.


n. However, when i open the individual shapes/polygons within the shapefile, the coordinates are still latitude and longitude. why does this happen?


----EDIT 1-----


from pyproj import Proj, transform
import fiona
from fiona.crs import from_epsg

dest_crs = from_epsg(4269)
shape = fiona.open("Sample.shp")

original = Proj(shape.crs) # EPSG:4326 in your case
destination = Proj('+proj=lcc +lat_1=36.41666666666666 +lat_2=35.25 +lat_0=34.33333333333334 +lon_0=-86 +x_0=600000 +y_0=0 +ellps=GRS80 +datum=NAD83 +no_defs')
with fiona.open('new.shp', 'w', 'ESRI Shapefile',shape.schema.copy(),crs = dest_crs) as output:
for feat in shape:
print feat['geometry']['coordinates']
for counter in range(0,len(feat['geometry']['coordinates'][0])):
long,lat = feat['geometry']['coordinates'][0][counter]
x,y = transform(original, destination,long,lat)
feat['geometry']['coordinates'][0][counter] = (x,y)
output.write(feat)



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...