Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ogr2ogr wont import the result geojson #13

Closed
acalcutt opened this issue Mar 11, 2021 · 2 comments
Closed

ogr2ogr wont import the result geojson #13

acalcutt opened this issue Mar 11, 2021 · 2 comments

Comments

@acalcutt
Copy link

acalcutt commented Mar 11, 2021

Hi ungarj or anyone who may be able to point me in the right direction

I am trying to make a lake centerlines geojson file similar to the osm-lakelines project, which looks like it uses the older create_centerlines.py to make this geojson file https://github.com/lukasmartinelli/osm-lakelines/releases/download/v0.9/lake_centerline.geojson

Pulling the steps from the docker images there it seems these would be the steps
1.) Import the lake geometry into postgresql using imposm
2.) Export the geometry from postgresql into a shape file using pgsql2shp
3.) Calculate the centerlines using label_centerlines

I made did the following in bash to generate the file
( https://github.com/acalcutt/osm-lakelines/ )

imposm import -connection "$PG_CONNECT" -mapping "$MAPPING_YAML" -overwritecache -cachedir "$IMPOSM3_CACHE_DIR" -read "$FULL_PBF" -dbschema-import="$DB_SCHEMA" -write

query="SELECT osm_id, ST_SimplifyPreserveTopology(geometry, 100) AS geometry FROM osm_lake_polygon WHERE area > 2 * 1000 * 1000 AND ST_GeometryType(geometry)='ST_Polygon' AND name <> '' ORDER BY area DESC"

pgsql2shp -f "$CENTERLINES_SHP" -h "$POSTGRES_HOST" -u "$POSTGRES_USER" -P "$POSTGRES_PASS" "$POSTGRES_DB" "$query"

label_centerlines --output_driver GeoJSON "$CENTERLINES_SHP" "$CENTERLINES_GEOJSON"

This all seemed to work, but ogr2ogr will not load the resulting file.

ogr2ogr -progress -f Postgresql -s_srs EPSG:4326 -t_srs EPSG:3857 "PG:dbname=osm user=postgres host=localhost password=pgpassword port=5432" -lco OVERWRITE=YES -overwrite -nln "lake_centerline" "data/osm_lake_centerline.geojson"
ERROR 1: Failed to reproject feature 0 (geometry probably out of source or destination SRS).
ERROR 1: Terminating translation prematurely after failed
translation of layer osm_lake_centerline (use -skipfailures to skip errors)

When I compare it with the origional file the co-ordinates seem much different. for example

In the old file I see
{ "type": "Feature", "properties": { "OSM_ID": -6343.000000 }, "geometry": { "type": "LineString", "coordinates": [ [ -6.160017741542741, 57.202632052397163 ], [ -6.160017789121379, 57.20263208363577 ], [ -6.160017811116719, 57.202632126970215 ] ] } },

but in the file I made the co-ordinates are much bigger numbers
{ "type": "Feature", "properties": { "OSM_ID": -6343.0 }, "geometry": { "type": "LineString", "coordinates": [ [ -685730.038266069372185, 7801648.177360998466611 ], [ -685730.043562498758547, 7801648.183780899271369 ], [ -685730.046011009137146, 7801648.192686640657485 ] ] } },

I also notice the projections is "urn:ogc:def:crs:OGC:1.3:CRS84" vs "urn:ogc:def:crs:EPSG::3857"

So i guess my question is why the difference in numbers? am I exporting the shape file incorrectly? Is the newer (non .py) version of lake centerlines working differently? Anybody have any tips that may help me finally make this file?

The shape file and geojson I generated are up here if anyone wants to look at them https://github.com/acalcutt/osm-lakelines/releases/tag/v9.1

@acalcutt
Copy link
Author

acalcutt commented Mar 11, 2021

Looking at the shape file in google earth it seems at least valid shapes. the lake shapes match nicely with real lakes.
google_earth

@acalcutt
Copy link
Author

well I think I may have gotten ogr2ogr to import my file with less options. The options I had used came from the openmaptiles import processes, so I am hoping without them it still works.

This worked
PGCLIENTENCODING=UTF8 ogr2ogr -progress -f Postgresql "PG:$PGCONN" -lco OVERWRITE=YES -overwrite -nln "lake_centerline" "data/osm_lake_centerline.geojson"
0...10...20...30...40...50...60...70...80...90...100 - done.

So I guess I can close this and see if the next step actually works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant