6

I want to import GeoJSON avaliable in the following dump into PostGIS but I am not able to import it. I already imported geousa data available in this public dump into MongoDB smoothly. Let me know is there a way to import this data directly or through MongoDB?

As this data is huge please check following data:

{"geometry": {"type": "Point", "coordinates": [19.056792, 47.490894]}, "type": "Feature",
"id": "SG_1iYphlxn9BSHyGrpv1aXKc_47.490894_19.056792@1308163237",
"properties": {"website": "http://mito.hu", "city": "Budapest",
"name": "Mito Europe", "tags": ["online", "communication", "design",
"branding", "development", "mito"], "country": "HU", "classifiers":
[{"category": "Professional", "type": "Services", "subcategory": "Advertising"}], "href": 
"http://api.simplegeo.com/1.0/features/SG_1iYphlxn9BSHyGrpv1aXKc_47.490894_19.056792@1308163237.json",
"address": "N\u00e1dor u. 23.", "owner": "simplegeo", "postcode": "1051"}}

http://s3.amazonaws.com/simplegeo-public/places_dump_20110628.zip

  • 3
    You should warn that your dataset is 2.2 GB. For making it more attractive to help you, could you prepare test data with just couple of features? That is well enough for testing. – user30184 Dec 1 '15 at 6:45
  • added data format for reference. – tryingsomethingnew Dec 1 '15 at 7:03
  • 1
    How have you tried to import the data, and what is the error message? – til_b Dec 1 '15 at 7:46
  • GDAL reads that one feature fine. You can test it yourself by saving it on the disk and running ogrinfo -al sample.json. You should really tell what you did and how did it fail. – user30184 Dec 1 '15 at 12:22
  • I executed: ogr2ogr -f "PostgreSQL" PG:"dbname=my_database user=postgres" "source.geojson" but I am getting error as: FAILURE Unable to open datasource `source.geojson' with the following drivers. (showing list of drivers) – tryingsomethingnew Dec 1 '15 at 18:24
15

You can use PostGIS's ST_GeomFromGeoJSON to bring in just the geometry part of the GeoJSON.

Better yet, you can use ogr2ogr to import the entire JSON document:

ogr2ogr -f "PostgreSQL" PG:"dbname=my_database user=postgres" "source_data.json" -nln destination_table -append

(I haven't tested this with your data, add a comment if you have issues.)

  • 1
    I am getting error as : FAILURE Unable to open datasource `source.geojson' with the following drivers. (showing list of drivers). – tryingsomethingnew Dec 1 '15 at 18:22
  • That has to be the full path to your geojson – Richard Law Dec 1 '15 at 18:49
  • I added full path as well, still I am getting the same error. – tryingsomethingnew Dec 1 '15 at 18:50
  • 1
    gdal-bin is already installed in my system (ubuntu). – tryingsomethingnew Dec 1 '15 at 19:21
  • 1
    I'm not going to download 2GB to look, but are your features a feature collection? – Richard Law Dec 1 '15 at 21:06
2
./ogr2ogr -f "PostgreSQL" PG:"dbname=theDatabaseName user=postgres" "/Users/dev/Downloads/theGeometry.json" -where "name not like 'Whatever%'" -nln theFeatureName -overwrite

ogr2ogr displays a list of drivers when the file is not found. in that case just pass in the full path to the json file

0

I try to use in python your suggestion for a list of big geojson files (like 30GB each one) and the ogr2ogr crashs.

import subprocess

dumpJson = 'ogr2ogr -f "PostgreSQL" PG:"dbname=DB user=postgres host=localhost port=4532" "/path/to/file/bigfile.json" -nln public.bigfile'

subprocess.call(dumpJson , shell=True)

ERROR 1: JSON parsing error: buffer size overflow (at offset 0) ERROR 4: Failed to read GeoJSON data FAILURE: Unable to open datasource/path/to/file/bigfile.json' with the following drivers.....`

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.