[postgis-users] Help on using Ogr2ogr to load dxf data to postgis

140 views
Skip to first unread message

Pieri70

unread,
Oct 12, 2012, 8:21:05 AM10/12/12
to postgi...@postgis.refractions.net
Hello
I'm trying to load a thousand dxf files to postgis using ogr2ogr (windows xp
postgres9/postgis2).
the syntax I use is:
ogr2ogr --config DXF_INLINE_BLOCKS FALSE --config DXF_MERGE_BLOCK_GEOMETRIES
FALSE -f "PostgreSQL" PG:"host=localhost user=postgres dbname=mydbname
password=mypassword" mydxf.DXF -overwrite entities

This creates a table called entities that collect point and lines and a
geometry column wkb_geometry with a coord dimension integer 2 and a srid 0

My questions are:
Is there the possibility to filter unwanted layer from dxf before insert
them into the entities table via ogr?
and
is there the possibility to convert closed polylines to polygons?
and
how can I set the correct coord space (3D) and srid?
Thanks in advance
Pietro



--
View this message in context: http://postgis.17.n6.nabble.com/Help-on-using-Ogr2ogr-to-load-dxf-data-to-postgis-tp5000446.html
Sent from the PostGIS - User mailing list archive at Nabble.com.
_______________________________________________
postgis-users mailing list
postgi...@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

Paolo Corti

unread,
Oct 12, 2012, 8:48:48 AM10/12/12
to PostGIS Users Discussion
Hi
you'd better do asking to gdal-dev list, as it is a GDAL question. Anyway:

On Fri, Oct 12, 2012 at 2:21 PM, Pieri70 <pier...@gmail.com> wrote:
> Hello
> I'm trying to load a thousand dxf files to postgis using ogr2ogr (windows xp
> postgres9/postgis2).
> the syntax I use is:
> ogr2ogr --config DXF_INLINE_BLOCKS FALSE --config DXF_MERGE_BLOCK_GEOMETRIES
> FALSE -f "PostgreSQL" PG:"host=localhost user=postgres dbname=mydbname
> password=mypassword" mydxf.DXF -overwrite entities
>
> This creates a table called entities that collect point and lines and a
> geometry column wkb_geometry with a coord dimension integer 2 and a srid 0
>
> My questions are:
> Is there the possibility to filter unwanted layer from dxf before insert
> them into the entities table via ogr?

I have not big experience with DXF driver, but the way you are going
you are just copying all of the layers from the .dxf file.
You can copy layer by layer (running the script for each layer)
specifying its name after input file, something like this:

ogr2ogr -f "PostgreSQL" PG:"host=localhost user=postgres
dbname=mydbname password=mypassword" mydxf.dxf layername -overwrite
entities

> and
> is there the possibility to convert closed polylines to polygons?

You could use the -nlt type option. I am sure it works for promoting
geometries to multi geometries and the other way, but I have never
tried for building polygons to polylines.
Otherwise use ST_Polygonize PostGIS function after the import.

> and
> how can I set the correct coord space (3D) and srid?

please refer to ogr2ogr [1] doc page
regards
p

[1] http://www.gdal.org/ogr2ogr.html

--
Paolo Corti
Geospatial software developer
web: http://www.paolocorti.net
twitter: @capooti
skype: capooti

Pieri70

unread,
Oct 12, 2012, 2:28:36 PM10/12/12
to postgi...@postgis.refractions.net
Hi Paolo, thanks.
Running the script for each layer assume that I know every layer inside each
dxf.
That's not possible because the content of a dxf depend on its location.
A dxf locate in mountain has different layers of a dxf representing a
seaside city..
But I know all layers that I don't want to load, because all them begin
with "X" (they are filling meshes).
So I have to specify the selection with some query like SELECT * from mydxf
where layer name not like 'X*'
I'll try to submit this question to gdal forum.
Bie
Pietro



--
View this message in context: http://postgis.17.n6.nabble.com/Help-on-using-Ogr2ogr-to-load-dxf-data-to-postgis-tp5000446p5000471.html
Sent from the PostGIS - User mailing list archive at Nabble.com.

Pieri70

unread,
Oct 16, 2012, 9:26:36 AM10/16/12
to postgi...@postgis.refractions.net
After googlin' around I get an answer myself..

This is the string I use to load a dxf file to postgis without any Layer
that begin with "X":

ogr2ogr --config DXF_INLINE_BLOCKS FALSE --config DXF_MERGE_BLOCK_GEOMETRIES
FALSE -f "PostgreSQL" PG:"host=localhost user=postgres dbname=mydb
password=myPassw" mydxf.dxf -where "Layer NOT LIKE 'X%'" -overwrite entities

bie
Pietro



--
View this message in context: http://postgis.17.n6.nabble.com/Help-on-using-Ogr2ogr-to-load-dxf-data-to-postgis-tp5000446p5000516.html
Reply all
Reply to author
Forward
0 new messages