Re: [GeoScript] Unable to export layer to shapefile

427 views
Skip to first unread message

Jared Erickson

unread,
Dec 31, 2012, 10:54:02 PM12/31/12
to geos...@googlegroups.com
Hi Stefan,

This appears to be a GeoTools problem, so this might help:


You might also try outputting to a difference Workspace (like H2) to confirm that its a Shapefile problem.  Could you include the full stack trace?

Thanks,
Jared

On Dec 30, 2012, at 1:01 PM, Stefan Ziegler wrote:

Hi 

I'm trying to export some postgis layers to shapefile:

pg = new PostGIS([schema: 'av_avwmsde_t', user: 'stefan', password: 'XXXXX'], 'rosebud')
layer = pg.get("mbfs")

Directory dir = new Directory("/home/stefan/tmp/geo/")
dir.add(layer)

This throws the following error:

Caught: java.io.IOException: Current fid index is null, next must be called before write()
java.io.IOException: Current fid index is null, next must be called before write()
at org.geotools.data.shapefile.indexed.IndexedFidWriter.write(IndexedFidWriter.java:252)
at org.geotools.data.shapefile.indexed.IndexedShapefileFeatureWriter.write(IndexedShapefileFeatureWriter.java:101)
at org.geotools.data.shapefile.ShapefileFeatureWriter.close(ShapefileFeatureWriter.java:231)
at org.geotools.data.shapefile.indexed.IndexedShapefileFeatureWriter.close(IndexedShapefileFeatureWriter.java:109)
at org.geotools.data.InProcessLockingManager$1.close(InProcessLockingManager.java:350)
at org.geotools.data.AbstractFeatureStore.addFeatures(AbstractFeatureStore.java:329)
at org.geotools.data.directory.DirectoryFeatureStore.addFeatures(DirectoryFeatureStore.java:104)
at org.geotools.data.FeatureStore$addFeatures.call(Unknown Source)
at geoscript.workspace.Workspace.add(Workspace.groovy:152)
at geoscript.workspace.Workspace.add(Workspace.groovy)
at geoscript.workspace.Workspace$add$0.callCurrent(Unknown Source)
at geoscript.workspace.Workspace.add(Workspace.groovy:127)
at geoscript.workspace.Workspace$add.call(Unknown Source)
at exportPostgisToShapefile.run(exportPostgisToShapefile.groovy:38)

I first thought that it is related to the shapefile restrictions but the attribute names are truncated fine. It seems that it has something to do with the position of the geometry column. This table definitions works:

CREATE TABLE av_avwmsde_t.mbsf_qgis_geometrie
(
  ogc_fid serial NOT NULL,
  geometrie geometry,
  bfsnr integer,
  "name" character varying(254),
  CONSTRAINT mbsf_qgis_geometrie_pkey PRIMARY KEY (ogc_fid),
  CONSTRAINT enforce_dims_geometrie CHECK (st_ndims(geometrie) = 2),
  CONSTRAINT enforce_geotype_geometrie CHECK (geometrytype(geometrie) = 'POLYGON'::text OR geometrie IS NULL),
  CONSTRAINT enforce_srid_geometrie CHECK (st_srid(geometrie) = 21781)
)
WITH (
  OIDS=FALSE
);

This does *not* work:

CREATE TABLE av_avwmsde_t.mbsf
(
  ogc_fid serial NOT NULL,
  bfsnr integer,
  "name" character varying,
  geometrie geometry,
  CONSTRAINT mbsf_pkey PRIMARY KEY (ogc_fid)
)
WITH (
  OIDS=FALSE
);

If there is a primary key (ogc_fid in the example) the geometry column has to be the second column. If there is no primary key (e.g. a view) the geometry column has to be first. Can this be reproduced? And is this Geoscript related (or rather Geotools)?

I'm using geoscript-groovy master from github.

Best regards
Stefan

--
You received this message because you are subscribed to the GeoScript mailing list.
To post to this group, send email to geos...@googlegroups.com
To unsubscribe from this group, send email to geoscript+...@googlegroups.com
Visit this group at http://groups.google.com/group/geoscript or see http://geoscript.org

Stefan Ziegler

unread,
Jan 1, 2013, 5:53:35 PM1/1/13
to geos...@googlegroups.com
Hi Jared

yes, I saw the thread. But it seems he had too long russian strings. I tried to export the layer to a properties file which works fine.

I wrote the same export in pure Geotools and got the same error and behaviour:

Jan 1, 2013 10:44:17 PM java.util.prefs.FileSystemPreferences$7 run
WARNING: Prefs file removed in background /home/stefan/.java/.userPrefs/org/geotools/referencing/wkt/prefs.xml
java.io.IOException: Current fid index is null, next must be called before write()
at org.geotools.data.shapefile.indexed.IndexedFidWriter.write(IndexedFidWriter.java:252)
at org.geotools.data.shapefile.indexed.IndexedShapefileFeatureWriter.write(IndexedShapefileFeatureWriter.java:101)
at org.geotools.data.shapefile.ShapefileFeatureWriter.close(ShapefileFeatureWriter.java:231)
at org.geotools.data.shapefile.indexed.IndexedShapefileFeatureWriter.close(IndexedShapefileFeatureWriter.java:109)
at org.geotools.data.TransactionStateDiff.applyDiff(TransactionStateDiff.java:277)
at org.geotools.data.TransactionStateDiff.commit(TransactionStateDiff.java:148)
at org.geotools.data.DefaultTransaction.commit(DefaultTransaction.java:183)
at org.catais.App.main(App.java:84)
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to com.vividsolutions.jts.geom.Geometry
at org.geotools.data.shapefile.ShapefileFeatureWriter.write(ShapefileFeatureWriter.java:362)
at org.geotools.data.shapefile.indexed.IndexedShapefileFeatureWriter.write(IndexedShapefileFeatureWriter.java:102)
at org.geotools.data.TransactionStateDiff.applyDiff(TransactionStateDiff.java:257)
... 3 more

So it really seems to be a Geotools issue (having some problems with the geometry columns position). 

Btw: is there a way to force to output the primary key attribute? This attribute is not writtten.

regards
Stefan
Reply all
Reply to author
Forward
0 new messages