Tag Info

Hot answers tagged

11

Assuming you want to reproject a shapefile, one way within QGIS is to load the file, right-click on the layer, select Save As…, and then the following window appears: If you click browse beside CRS you can choose a new projection to save your file in. EDIT: To reproject all shapfiles in the one folder, something like this could work: set ...


10

You miss a minus sign before where and the select is not necessary, so it should be: ogr2ogr -where ID="1" outfile.shp infile.shp or if you have to do more complex query on your input data: ogr2ogr -sql "SELECT * FROM infile WHERE ID='1'" outfile.shp infile.shp If ID is a field of Integer type, substitute ID='1' with ID=1. Notes: -f "ESRI Shapefile" ...


9

On Windows, for the current and sub-directories under the current, try this command: for /R %f in (*.shp) do ogr2ogr -f "MapInfo File" "%~dpnf.tab" "%f" To briefly explain the trickery of what is going on here, %~dpnf.tab uses the variable %f, with which it adds the driver letter, path name (i.e., folder or directory), and extracts the file name (without ...


9

Figured it out by reading the OGR SQL documentation at http://www.gdal.org/ogr/ogr_sql.html This works, using one command and one output file per geometry type: $ ogr2ogr -where "OGR_GEOMETRY='Point'" -f "ESRI Shapefile" transit_points.shp transit.kml $ ogr2ogr -where "OGR_GEOMETRY='LineString'" -f "ESRI Shapefile" transit_linestrings.shp transit.kml


8

To answer my own question on how to combine both the .dbx (properties) and the .shp (geometries) into a single JSON file: The problem I did not see is that all file names must be lower case to enable ogr2ogr to do the conversion. That should not be neccessary if your file system is case-insensitive but mine is. With this requirements fulfilled ogr2ogr is ...


8

I would use the -sql option, and import the shapefile in the following way: ogr2ogr -update -append %destination% %n2% -sql 'SELECT "%n2%" as SHAPE_ORIG, field1, field2, ... FROM %n2%'


8

Using Homebrew you should: brew install gdal --with-postgresql or with older versions of gdal: brew install gdal --with-postgres if you have already installed gdal with brew before but without postgresql support, just brew uninstall gdal


8

SpatialLite has no way of converting multi-geometries to single-parts itself. There are some 'CastTo' functions but they are for special cases (where your multigeometry contains a single geometry - it won't fan-out). I have seen a reference to a function in the SpatialLite GUI but never found it (perhaps you need to compile from the latest source code. ...


8

SRS is the spatial reference system that your data are stored in. The terms SRS and CRS are often used interchangeably. The SRS defines the projection and map units (commonly degrees or meters) of the data. In OGR2OGR the -s_srs switch allows you to manually specify an SRS, which may be different to the SRS recorded with the input data. You might use ...


7

there are some ways for merging shapefiles. if you want to merge layers as a one layer, you can use MMqgis tools for merging... if you want to merge all shapefiles under a folder, you can use DARREN COPE simple code here. mkdir merged for %f in (*.shp) do ( if not exist merged\merged.shp ( ogr2ogr -f “esri shapefile” merged\merged.shp %f) else ( ...


7

you can use ST_GeomFromKML as this page. SELECT ST_GeomFromKML(' <LineString> <coordinates>-71.1663,42.2614 -71.1667,42.2616</coordinates> </LineString>'); or you can use ogr2ogr as following to process entire KML files; ogr2ogr -f "PostgreSQL" PG:"host=yourhost user=youruser ...


7

OK, playing around with different projections, scales and translations in d3 solved my problem. Since the default projection when using d3.geo.path() is albersUsa there was good reason to try some other projections. I suppose the problem could have been solved easier using the right EPSG specification when converting the shape file but these obscure numbers ...


7

You are looking for the -progress switch ogr2ogr -progress ... You can see the other options by doing ogr2ogr --help Usage: ogr2ogr [--help-general] [-skipfailures] [-append] [-update] [-select field_list] [-where restricted_where] [-progress] [-sql <sql statement>] [-dialect dialect] [-preserve_fid] ...


7

Two possibilities: Use wildcards to process all files in a directory: FOR %%F in (D:\Karten\shp\Gemeinden\*.shp) DO ogr2ogr -t_srs EPSG:31466 D:\Karten\shp\neu\%%~nxF %%F Use quotation marks around path and filename: ogr2ogr -t_srs EPSG:31466 "D:\Karten\shp\Test 1.shp" "D:\Karten\shp\Test 2.shp" EDIT This one works for me: for /R %%F in (*.shp) do ...


7

As 102100 and 3857 are mathematically identical, I think you can safely ignore the errors and just continue with overriding the source srs using the -s_srs flag. You can try adding the definition for 102100 in your $GDAL_DATA$ but it's not really recommended. If you really want to do it though, here's the method and the accompanying warning from Frank ...


7

There is, yes, using a combination of row_to_json, array_to_json, array_agg and ST_AsGeoJSON. I realize, on rereading your question, that you asked for ogr2ogr approach, but seeing as your source is Postgis, I thought you might appreciate a pure Postgres/Postgis approach. I have used this approach with Google Maps, so it works well if you need to create ...


6

Grab a copy of the ogr2ogr Python port, which is distributed with the GDAL source code download or can be found here: http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/ogr2ogr.py Once you import that into your code, you can use it like this: import ogr2ogr def main(): #note: main is expecting sys.argv, where the first argument is the script name ...


6

You have two ways of reducing the file size: Remove all the pretty formatting and redundant white space. In some 'XML-style' files this can be a surprisingly large amount and can easily double or even treble your file size. However I doubt it accounts for the difference in your volume and the data you link to above. Reduce the volume of actual data ...


6

Use the -nlt option. In this case you want: -nlt MULTILINESTRING There is also PROMOTE_TO_MULTI (GDAL 1.10 and later), which chooses either MULTILINESTRING or MULTIPOLYGON depending on the input layer. The use case for this is "doing a mass conversion of shapefiles that [mix] different types of geometries".


5

With small scripting it would be doable. With something like following you should be able to add column to a shapefile in all shapefiles in a folder, and merge them to merged.shp file for %f in (*.shp) do ( ogrinfo %f -sql "ALTER TABLE %f ADD COLUMN filename character(15)" ogrinfo %f -sql "UPDATE TABLE %f filename = '%f'" ogr2ogr -update -append ...


5

All that's happening, as far as I can see, is that it cannot find a file called spans. Make sure you provide the path to the file (either relative or absolute), and add the extension, which will be .shp in this case. If you're still having problems, then it might be that you have a broken Shapefile, see if you can get useful information from ogrinfo, and ...


5

Save yourself some pain and use the Kyngchaos packaged binaries/frameworks for OSX.GDAL-Complete is the one you are looking for. Another option is to use HomeBrew.


5

i wrote some downloadable code for that. A simple python program for combine shapefiles in many ways: http://furiousgis.blogspot.it/2012/05/python-shapefile-merger-utility.html By default performs the dbf schemes union and it adds an attribute filled with the source shapefile name, so you can recognize records. This is the commandline for your needs: ...


5

try adding -nlt NONE, in case it's a table without geometries


5

Say you have three DBF files with the same field structure (schema), and you want to combine them into one all.dbf. From a system shell, use ogr2ogr with the -append flag: $ ogr2ogr -append all.dbf a.dbf $ ogr2ogr -append all.dbf b.dbf $ ogr2ogr -append all.dbf c.dbf These files can be either shapefiles or sole DBF files. It will work either way.


5

Ogr2ogr translates vector data sources between different formats. Shape file is one kind of data source format but WKT is not. WKT is just a way to represent geometries in a human understandable way. Data source consists of features/objects that consists of a geometry and attributes. The ogr2ogr command you specified in your previous question translates ...


5

You have to force the SHP geometry type (because the geometry type of GeoJSON Geometry Collection is not supported in SHPs) and use the -skipfailures option: ogr2ogr -nlt POINT -skipfailures points.shp geojsonfile.json OGRGeoJSON ogr2ogr -nlt LINESTRING -skipfailures linestrings.shp geojsonfile.json OGRGeoJSON ogr2ogr -nlt POLYGON -skipfailures ...


5

And, after a bit more reading the ogr2ogr help I found the answer more easily than I expected. ogr2ogr -f "PostgreSQL" PG:"dbname=db" spatialitedb -sql "SELECT * FROM table" -dialect spatialite -nln new_table EDIT: As suggested by user30184 in the comments a cleaner, simpler method is: ogr2ogr -f "PostgreSQL" PG:"dbname=db" spatialitedb ...


5

OGR has its own idiom for stdin, /vsistdin/. Use that as ogr2ogr's first argument (the dst_datasource_name) and you can pipe curl's output to it: curl "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_50m_admin_0_countries.geojson" | ogr2ogr -f "KML" countries.kml /vsistdin/


4

Using GDAL >= 1.10.0 and its OGR Virtual Format, we can write a VRT file named, for example, merge.vrt (see Example: Union layer (GDAL >= 1.10.0)): <OGRVRTDataSource> <OGRVRTUnionLayer name="unionLayer"> <OGRVRTLayer name="source1"> <SrcDataSource>source1.shp</SrcDataSource> </OGRVRTLayer> ...



Only top voted, non community-wiki answers of a minimum length are eligible