0

I am trying to convert a simple point object created using shapely to a shapefile using fiona as instructed in this post. I pretty much followed line by line except that I changed the crs as I need it in another coordinate system.

The code I used:

##Creating the point

    o = Point(-75.478003, 40.603155) 
    o

##Convert the point to shapefile using code from @Mike T :

    from shapely.geometry import mapping
    import fiona

    schema = {
        'geometry': 'Point',
        'properties': {'id': 'int'},
    }

    with fiona.open('L:\lvpcgis\BowenLiuTemporary\ExtendLinesToLayer\my_shp1.shp', 'w', 'ESRI Shapefile', schema, 
    crs=bldg.crs) as c:

        c.write({
            'geometry': mapping(o),
            'properties': {'id': 1},
        })

The only thing I changed here is crs by specifying crs = bldg.crs

bldg. crs
{'proj': 'lcc',
 'lat_1': 39.93333333333333,
 'lat_2': 40.96666666666667,
 'lat_0': 39.33333333333334,
 'lon_0': -77.75,
 'x_0': 600000,
 'y_0': 0,
 'datum': 'NAD83',
 'units': 'us-ft',
 'no_defs': True}

After running the code, I get a point shapefile my_shp1. However, when I add it in ArcGIS to check its accuracy, it shows up at the wrong location with lon, lat of 84.6941252°W 39.1210089°N with a projected coordinate system of "Lambert Conformal Conic" and geographic coordinate system of EPSG:4269.

I realize I must have somehow the coordinate system somehow but I just don't know where.

And it'd be better if there is a better way to convert shapely object to a shapefile.

Vince
  • 20,017
  • 15
  • 45
  • 64
Bowen Liu
  • 663
  • 8
  • 18
  • You need to reproject the input coordinates to the LCC CRS. See this question. – mkennedy Apr 24 '19 at 19:28
  • @mkennedy Could you care to elaborate a bit please? I already reprojected the coordinates in my code with the crs=bldg.crs part. Why would I want to reproject it to the LCC CRS? I never wanted it in LCC anyway. Thanks. – Bowen Liu Apr 24 '19 at 19:39
  • I'm familiar with CRS, not with shapely/fiona, but I'm pretty sure you identified the data as using the LCC definition, when the coordinates are actually lat-lon. Or vice versa, reading your text again. You have to reconcile the LCC and lat-lon data somehow. – mkennedy Apr 24 '19 at 19:44
  • @mkennedy Thanks. I am also seeing crs mismatch UserWarning everywhere now. Please help me out. Please help me out. With my own knowledge of crs, I will never finish this on time. I created a new bldg geodataframe and somehow its proj is lcc. At which step did I identify the data as LCC? Thanks again! – Bowen Liu Apr 24 '19 at 19:56
  • 1
    You need to reproject your point. Just assigning the crs to bldg.crs doesn't change the coordinates of the point. Use pyprog transform as per the duplicate post https://gis.stackexchange.com/q/121441/2856 and change the lcc crs to bldg.crs. – user2856 Apr 24 '19 at 23:17

0 Answers0