[gdal-dev] DXF to Postgis using ogr2ogr

Bob Pawley rjpawley at shaw.ca
Tue Dec 27 13:48:33 EST 2011


Something is still not penetrating this thick skull of mine.

When I run 

ogr2ogr --config DXF_INLINE_BLOCKS FALSE  --config        DXF_MERGE_BLOCK_GEOMETRIES FALSE  -f "PostgreSQL" PG:"host=localhost user=postgres dbname=db password=pass"  W_Works.dxf -overwrite -skipfailures  -sql "SELECT ST_Translate(ST_Scale(ST_Rotate((ST_Dump(b.wkb_geometry)).geom, e.blockangle / 180 * PI()), e.blockscale[1], e.blockscale[2]), ST_X(e.wkb_geometry), ST_Y(e.wkb_geometry)) AS wkb_geometry, CASE WHEN b.ogr_style IS NOT NULL THEN b.ogr_style ELSE e.ogr_style END AS ogr_style, e.layer, e.linetype, e.subclasses, b.text FROM entities e INNER JOIN blocks b USING (blockname)" 

I get error - Undefined function `st_dump`used.

When I run a simplified version 

ogr2ogr --config DXF_INLINE_BLOCKS FALSE --config  DXF_MERGE_BLOCK_GEOMETRIES FALSE  -f "PostgreSQL" PG:"host=localhost user=postgres dbname=db password=pass" W_Works.dxf    -overwrite -skipfailures  -sql "SELECT wkb_geometry From entities"

I get error - unrecognized field name wkb_geometry

In the last, when I substitute wkb_geometry for the blocks (name, angle, scale) or text I get no errors.

In all of the commands I`ve run, the block table remains empty.

Bob



From: Ralf Suhr 
Sent: Wednesday, December 21, 2011 1:30 AM
To: Bob Pawley 
Cc: gdal-dev at lists.osgeo.org 
Subject: Re: [gdal-dev] DXF to Postgis using ogr2ogr

On Import you can't use -nln option or you run ogr2ogr to times. One for entities layer and secound for blocks. 


ogr2ogr -f postgresql -nln myentities PG:"..." W_Works.dxf entities

ogr2ogr -f postgresql -nln myblocks PG:"..." W_Works.dxf blocks


If you haven't the legacy functions import into your postgis installation you need to prefix with "ST_" Translate, Scale, Rotate and Dump.

On Dienstag 20 Dezember 2011 22:30:20 Bob Pawley wrote:

> When I run

> ogrinfo --config DXF_INLINE_BLOCKS FALSE W_Works.dxf

> 

> it results in this message

> 

> Open of `W_Works.dxf'

> using driver `DXF' successful.

> 1: blocks

> 2: entities

> 

> And I’m using DraftSight as a drawing viewer.All of the information I want

> is on the model, but it still won’t import unless I explode the dxf file

> before saving.

> 

> I did try running your suggested sql command. I got an error “Undefined

> function ‘Dump’ used.

> 

> I also used the sql suggestion as a trigger function on the import table.

> Neither blocks nor entities were recognized.

> 

> Bob

> 

> From: Ralf Suhr

> Sent: Monday, December 19, 2011 8:52 AM

> To: Bob Pawley

> Cc: gdal-dev at lists.osgeo.org

> Subject: Re: [gdal-dev] DXF to Postgis using ogr2ogr

> 

> http://www.gdal.org/ogr/drv_dxf.html

> 

> 

> 

> Does ogrinfo print out the "blocks" layer?

> 

> ogrinfo --config DXF_INLINE_BLOCKS FALSE File.dxf

> 

> INFO: Open of `File.dxf'

> 

> using driver `DXF' successful.

> 

> 1: blocks

> 

> 2: entities

> 

> 

> 

> To see what can be imported by ogr use a dxfviewer that display only the

> model space. I have tested ogr with dxf version up to AC1018 without

> problems except the paper space.

> 

> 

> 

> 

> 

> Gr

> 

> Ralf

> 

> On Montag 19 Dezember 2011 17:21:58 Bob Pawley wrote:

> > Thanks Ralf

> > 

> > 

> > 

> > So far, I haven’t been able to populate the block columns unless I use a

> > 

> > DXF file which has been exploded before saving.

> > 

> > 

> > 

> > In all of my searching, I have not come across your suggestion of

> > 

> > dereferencing the block. Can you point me to some documentation?

> > 

> > 

> > 

> > Bob

> > 

> > 

> > 

> > 

> > 

> > From: Ralf Suhr

> > 

> > Sent: Monday, December 19, 2011 12:58 AM

> > 

> > To: gdal-dev at lists.osgeo.org

> > 

> > Cc: Bob Pawley

> > 

> > Subject: Re: [gdal-dev] DXF to Postgis using ogr2ogr

> > 

> > 

> > 

> > Hi Bob,

> > 

> > 

> > 

> > 

> > 

> > 

> > 

> > the dxf driver writes to tables "entities" and "blocks". You have to

> > 

> > dereference the block layer yourself.

> > 

> > 

> > 

> > 

> > 

> > 

> > 

> > SELECT Translate( Scale( Rotate((Dump(b.wkb_geometry)).geom, e.blockangle

> > /

> > 

> > 180 * PI()), e.blockscale[1], e.blockscale[2]), ST_X(e.wkb_geometry),

> > 

> > ST_Y(e.wkb_geometry)) AS wkb_geometry,

> > 

> > 

> > 

> > CASE WHEN b.ogr_style IS NOT NULL THEN b.ogr_style ELSE e.ogr_style END

> > AS

> > 

> > ogr_style,

> > 

> > 

> > 

> > e.layer,

> > 

> > 

> > 

> > e.linetype,

> > 

> > 

> > 

> > e.subclasses,

> > 

> > 

> > 

> > b.text

> > 

> > 

> > 

> > FROM entities e

> > 

> > 

> > 

> > INNER JOIN

> > 

> > 

> > 

> > blocks b USING (blockname);

> > 

> > 

> > 

> > 

> > 

> > 

> > 

> > Sometimes you have blocks with world coordinates and no connection in

> > 

> > entities.

> > 

> > 

> > 

> > SELECT (Dump(b.wkb_geometry)).geom AS wkb_geometry,

> > 

> > 

> > 

> > b.ogr_style,

> > 

> > 

> > 

> > b.layer,

> > 

> > 

> > 

> > b.linetype,

> > 

> > 

> > 

> > b.subclasses,

> > 

> > 

> > 

> > b.text

> > 

> > 

> > 

> > FROM blocks b

> > 

> > 

> > 

> > WHERE blockname NOT IN

> > 

> > 

> > 

> > (

> > 

> > 

> > 

> > SELECT DISTINCT blockname

> > 

> > 

> > 

> > FROM entities

> > 

> > 

> > 

> > WHERE blockname IS NOT NULL

> > 

> > 

> > 

> > );

> > 

> > 

> > 

> > 

> > 

> > 

> > 

> > Some newer DXF Formats can have features in paper space. This is now not

> > 

> > supported by ogr2ogr.

> > 

> > 

> > 

> > 

> > 

> > 

> > 

> > 

> > 

> > 

> > 

> > Gr

> > 

> > 

> > 

> > Ralf

> > 

> > On Freitag 16 Dezember 2011 22:14:38 Bob Pawley wrote:

> > > I have imported a dxf file into Postgis using the following command

> > > line

> > > 

> > > -

> > > 

> > > 

> > > 

> > > 

> > > 

> > > 

> > > 

> > > set DXF_INLINE_BLOCKS=FALSE&set DXF_MERGE_BLOCK_GEOMETRIES=FALSE&set

> > > 

> > > 

> > > 

> > > PGCLIENTENCODING=LATIN1&&ogr2ogr -f "PostgreSQL" PG:"host=localhost

> > > 

> > > 

> > > 

> > > user=postgres dbname=dbname password=pass" W_Works.dxf -nln Import_PID

> > > 

> > > 

> > > 

> > > -overwrite –skipfailures

> > > 

> > > 

> > > 

> > > 

> > > 

> > > 

> > > 

> > > All geometries are intact.

> > > 

> > > 

> > > 

> > > 

> > > 

> > > 

> > > 

> > > However, the text is part of the Linestring layer and not in the text

> > > 

> > > 

> > > 

> > > column of the Postgresql table.

> > > 

> > > 

> > > 

> > > 

> > > 

> > > 

> > > 

> > > Is this to be expected?

> > > 

> > > 

> > > 

> > > 

> > > 

> > > 

> > > 

> > > Is there some way of screening out the text as text and point geometry?

> > > 

> > > 

> > > 

> > > 

> > > 

> > > 

> > > 

> > > Bob


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20111227/061e5850/attachment-0001.html


More information about the gdal-dev mailing list