Hot answers tagged ogr2ogr
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
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. ...
6
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 ...
5
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 ...
5
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 ...
5
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 ...
5
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 ...
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 ...
4
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
4
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;
ogr2ogr -f 'ESRI Shapefile' outputkml.shp yourkml.kml
ogr2ogr -overwrite -f "PostgreSQL" ...
4
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 ...
4
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 ...
4
Is it possible to create CAD file from shapefile and also create CAD blocks from the database fields
FME can do Shape to AutoCAD Blocks
This was modified (for FME 2013) from the original on FMEPedia
http://fmepedia.safe.com/articles/How_To/Creating-AutoCAD-Blocks-with-FME
Product:
FME Desktop
http://www.safe.com/fme/fme-technology/fme-desktop/overview/
3
As Alex Markov said, the best way would be for you to use OGR.
You will need to do a script, but a very simple one. Basicly if you are using windows, all you have to do is run the following code in the command line (inside de desired folder):
for %f in (*.tab) do ogr2ogr -f "KML" %~nf.kml %f
Check this site, all is explained here:
...
3
Unfortunately, OGR sees the KML file as having 247 layers (ogrinfo doc.kml), which is why you see the mess.
I would do a direct KML -> PostGIS conversion. You can keep a clean PostGIS DB by using a schema to contain the mess temporarily. From your SQL:
CREATE SCHEMA import;
Now from your shell (I'm using OSGeo4W Shell):
$ ogr2ogr -append -f PostgreSQL ...
3
The GPX format assumes WGS84 datum (EPSG:4326). The shapefile in question has no defined projection (*.prj file). The ogr2ogr command thus assumes that your file is already in WGS84 and then calls an error when it comes across coordinates outside the valid range for WGS84.
To solve this problem, you need to find out what projection the shapefile is in and ...
3
vascobnunes, here's how I accomplished this problem by using a Python script to daisy-chain several ogr2ogr instructions together. You could easily convert it to a batch script, basically I just concatenate together ogr2ogr instructions (cmd), then execute them by calling os.system(cmd), passing-in the ogr2ogr command I concatenated together.
The secret ...
3
Add column with source filename from folder of shapefiles. Requires GDAL 1.10dev, my attempt to drop .shp extension isn't working - but overall, works. - I imagine it could be added to the lines that do merging with OGR.
for f in *.shp;
do
name=${f%.shp}
/Users/you/gdal_src/bin/ogrinfo $f -sql "ALTER TABLE $name ADD COLUMN filename character(21)"
...
3
You will probably find much better answers than I can give you at http://www.gis.usu.edu/~chrisg/python/2009/lectures/ospy_slides1.pdf and http://trac.osgeo.org/gdal/wiki/GdalOgrInPython.
Try there or another tutorial linked from the second URL and maybe ask another more specific question if you are stuck.
3
You are right, for a map of germany you need to change the default projection as it fits for USA data. It is centered somewhere in Kansas and for a map of size 960xsomething.
The correct parameters of course also depend on your map dimensions.
If you want to use the d3.geo.albers projection (best for coropleth maps) here are my parameters:
var w = 415;
...
3
Quoting from http://www.gdal.org/ogr/drv_shapefile.html :
An attempt is made to read the LDID/codepage setting from the .dbf
file and use it to translate string fields to UTF-8 on read, and back
when writing. LDID "87 / 0x57" is treated as ISO8859_1 which may not
be appropriate. The SHAPE_ENCODING configuration option may be used to
override the ...
3
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.
3
Have you tried accessing the database directly from MapInfo Professional or do you not have access to MapInfo Professional?
You could try:
create a view that selects all the columns from your table, uses the STGeomFromText to convert the WKT to a SQL Server spatial type
create an ODBC data source that connects to the database
create the MapCatalog in the ...
3
Not the operating system you want, but BaseCamp by Garmin can read your kml file, and exporting to csv gives a file that can be added with delimited text to QGIS. The data leads to Indonesia.
EDIT
Unfortunately, KML is not a very strict standard. That means that almost every form of data storage is allowed, as long as it is valid XML. The kml drivers ...
2
I believe that the driver currently only works fully one way (i.e. writing TO kml). It currently expects a Description field in the KML data and uses that for its attribute, but truncates the name to 'Descriptio' because of the shapefile's DBF field naming limitation.
However, there is a version of the KML driver in development that will do what you want ...
2
You can output to a shapefile with ogr2ogr (1.8) but will get truncated field contents or missing information.
For gdal <2.0 use:
ogr2ogr --config SHAPE_ENCODING UTF-8 -update -append output.shp /vsizip/vsicurl/http://www.hockeyarenas.net/hockeyarenas/downloads/kmz/World_Hockey_Arenas.zip/doc.kml -nln output -nlt GEOMETRY
For gdal >2.0 use:
ogr2ogr ...
2
i think there is a projection problem in this file . make a new file under the same dir as name of trees.prj and then past the following definition in it. then run your ogr2ogr command...
...
2
In the current ogr2ogr documentation it outlines the -nln property, which allows for specifying an alternate layer name. I don't know how new this is so you may need to download a new version, but it does work.
ogr2ogr -f KML some_output.kml example.geojson -nln SOMENAME
Using the above command on your example geojson produced the following results:
...
2
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.
2
Read up on os.system or os.popen or subprocess. Or just use ogr2ogr and your shell. Even cmd.exe (Windows) lets you loop over input files.
Only top voted, non community-wiki answers of a minimum length are eligible

