I have a json file that contains a lot of data with polygons, lines, points. But I can't exploit it to export the data in shapefile. Can someone help me on how to get there. The data is here.
https://www.sia.aviation-civile.gouv.fr/produits-numeriques-en-libre-disposition/donnees-zones-geographiques-uas.html
if someone can help me solve this problem.
You can't export all of it to one shapefile as it is not possible to mix geometry types in a shapefile, so you will need 3 shapefiles (points, lines, polygons).
I would make use of ogr2ogr the Swiss army knife of vector formats and use something like:
ogr2ogr -nlt POINT -skipfailures points.shp geojsonfile.json
ogr2ogr -nlt LINESTRING -skipfailures linestrings.shp geojsonfile.json
ogr2ogr -nlt POLYGON -skipfailures polygons.shp geojsonfile.json
Related
I need help reformatting a CSV file of polygons into a format readable by QGIS.
The data I downloaded has a bunch of seemingly unnecessary text before the coordinates of the polygons.
The coordinates are formatted like this:
{"geodesic":false,"type":"Polygon","coordinates":[[[-124.26718718727625,49.10353039748446],[-124.26664819810578,49.1037998920697],[-124.26718718727625,49.1037998920697],[-124.26718718727625,49.10353039748446]]]}
and I need them to be formatted like this:
MULTIPOLYGON [[[-124.26718718727625,49.10353039748446],[-124.26664819810578,49.1037998920697],[-124.26718718727625,49.1037998920697],[-124.26718718727625,49.10353039748446]]]
Lets say you have all your coordinates in a text file line by line you'd make a copy of your file, use NotePad++ and go through following steps:
Ctrl+H
Find what: ({"geodesic":false,"type":"Polygon","coordinates":)(.+)(\}$)
Replace with: MULTIPOLYGON \2
Search mode: Regular expression
Click on Replace All or Alt+A
Done ...
MULTIPOLYGON [[[-124.26718718727625,49.10353039748446],...,...,[-124.26718718727625,49.10353039748446]]]
MULTIPOLYGON [[[-124.26718718727625,49.10353039748446],...,...,[-124.26718718727625,49.10353039748446]]]
MULTIPOLYGON [[[-124.26718718727625,49.10353039748446],...,...,[-124.26718718727625,49.10353039748446]]]
MULTIPOLYGON [[[-124.26718718727625,49.10353039748446],...,...,[-124.26718718727625,49.10353039748446]]]
I've been using ogr2ogr to do most of what I need with shapefiles (including dissolving them). However, I find that for big ones, it takes a REALLY long time.
Here's an example of what I'm doing:
ogr2ogr new.shp old.shp -dialect sqlite -sql "SELECT ST_Union(geometry) FROM old"
In certain instances, one might want to dissolve common neighboring shapes (which is what I think is going on here in the above command). However, in my case I simply want to flatten the entire file and every shape in it regardless of the values (I've already isolated the shapes I need).
Is there a faster way to do this when you don't need to care about the values and just want a shape that outlines the array of shapes in the file?
If you have isolated the shapes, and they don't have any shared boundaries, they can be easily collected into a single MULTIPOLYGON using ST_Collect. This should be really fast and simple to do:
ogr2ogr gcol.shp old.shp -dialect sqlite -sql "SELECT ST_Collect(geometry) FROM old"
If the geometries overlap and the boundaries need to be "dissolved", then ST_Union must be used. Faster spatial unions are done with a cascaded union technique, described here for PostGIS. It is supported by OGR, but it doesn't seem to be done elegantly.
Here is a two step SQL query. First make a MULTIPOLYGON of everything with ST_Collect (this is fast), then do a self-union which should trigger a UnionCascaded() call.
ogr2ogr new.shp old.shp -dialect sqlite -sql "SELECT ST_Union(gcol, gcol) FROM (SELECT ST_Collect(geometry) AS gcol FROM old) AS f"
Or to better view the actual SQL statement:
SELECT ST_Union(gcol, gcol)
FROM (
SELECT ST_Collect(geometry) AS gcol
FROM old
) AS f
I've had better success (i.e. faster) by converting it to raster then back to vector. For example:
# convert the vector file old.shp to a raster file new.tif using a pixel size of XRES/YRES
gdal_rasterize -tr XRES YRES -burn 255 -ot Byte -co COMPRESS=DEFLATE old.shp new.tif
# convert the raster file new.tif to a vector file new.shp, using the same raster as a -mask speeds up the processing
gdal_polygonize.py -f 'ESRI Shapefile' -mask new.tif new.tif new.shp
# removes the DN attribute created by gdal_polygonize.py
ogrinfo new.shp -sql "ALTER TABLE new DROP COLUMN DN"
I'm trying to map some statistical data of Italy and I need the infrastructure (railway and motorway) on top of it.
The problem is that I'm not able to simplify the infrastructure json file.
I'm using the openstreetmap shape of Italy by geofabbriK: http://download.geofabrik.de/europe/italy.html#
I've converted the roads.shp to json selecting only motorway and and primary roads using this command:
ogr2ogr -f GeoJSON -where "type IN ('motorway', 'motorway_link', 'primary', 'primary_link')" -t_srs EPSG:4326 roads.json roads.shp
I get a 55Mb json file. You can download it here: http://www.danielepennati.com/prove/mapping/roads_mw_pr.zip
Than I tryed to simplify and convert it in topojson.
Whit no -s command the new json file is about 13Mb
If I use -s or --simplify-proportion with any value form 1 to 0 I always get a max semplification of 95% and a filesize of 11Mb
How can I get a more simplified topojson?
Thanks
daniele
I have an ascii text file containing location data (column 9-lat and 10-long) and intensity(column 20)
200010 207 020311 40658.5 406593 52 344927.31 7100203.50 -26.2078720 127.4491855 345060.64 7100369.14 26.4 650.3 628.0 55471.293 20.168 55648.817 55637.523 -146.062
the text file has many lines 10k+
I am trying to visualize this using GDAL, but not sure how to proceed.
Ideas?
Try QGis. It is free software for making maps with data.
GDAL is for doing sophisticated data transformations.
If your file is named viz.txt, then you can extract
and plot the data using the following commands:
$ awk '{print $9, $10, $20}' < viz.txt > viz2.txt
$ gnuplot
...
gnuplot> plot "viz2.txt" with points palette
This will give you a chart, nicely coloured by intensity.
If you want a more interactive solution, or to overlay the
data on a map, then you will have to use GIS software such
as ArcView, MapInfo or the free tools Generic Mapping Tools (GMT) or QGIS.
I've downloaded the latest set (2010) of TIGER edge shape files (ESRI shapefile format) from the US Census website and am loading them into MySQL using the GDAL ogr2ogr utility. A new table (geotest) does get created with a SHAPE column that has the geometry defined as a LINESTRING. However, I am seeing reversed latitude and longitude values that get reversed when running the following command:
ogr2ogr -f "MySQL" MySQL:"geo,user=myuser,host=localhost,password=mypwd" -nln geotest -nlt LINESTRING -append -a_srs "EPSG:4326" -lco engine=MYISAM tl_2010_01021_edges.shp
Mapping the latitude/longitude (after reversing them of course) they appear to be spot on so I suspect there is just something I am doing wrong or flag I am missing which is causing the latitude and longitudes to be transposed.
When I select the SHAPE column using astext() I get the following result:
LINESTRING(-86.69863 32.973164,-86.69853 32.97302,-86.69856 32.97287,-86.698613 32.972825,-86.6988 32.972825,-86.6989 32.972892,-86.6989 32.973002,-86.69874 32.97316,-86.69864 32.97318,-86.69863 32.973164)
Any ideas what I am doing wrong?