[Geoserver-users] WFS error performing insert: java.lang.String cannot be cast to com.vividsolutions.jts.geom.Geometry

Hi, list!

I’m trying to make a WFS insert transaction with OpenLayers to a GS 2.1.2 PostGIS layer.
My request is:

<wfs:Transaction xmlns:wfs=“http://www.opengis.net/wfs” service=“WFS” version=“1.0.0” xsi:schemaLocation=“http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”>
wfs:Insert
<feature:plots xmlns:feature=“landws”>
feature:the_geom
<gml:MultiPolygon xmlns:gml=“http://www.opengis.net/gml” srsName=“EPSG:900913”>
gml:polygonMember
gml:Polygon
gml:outerBoundaryIs
gml:LinearRing
<gml:coordinates decimal=“.” cs=“,” ts=" ">4112493.6591121,7609090.535939 4111461.7592304,7607867.5434866 4114041.5089347,7606701.8788054 4114098.8367059,7609472.7210804 4112493.6591121,7609090.535939</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</gml:polygonMember>
</gml:MultiPolygon>
</feature:the_geom>
</feature:plots>
</wfs:Insert>
</wfs:Transaction>

I get a wfs:FAILED/ status in the response.

The log says:
2011-12-13 21:24:27,583 INFO [geoserver.wfs] -

Request: getServiceInfo
2011-12-13 21:24:27,600 INFO [geoserver.gwc] - DataStoreChange: {landws}plots PreInsert
2011-12-13 21:24:27,604 ERROR [geoserver.wfs] - Transaction failed
org.geoserver.wfs.WFSTransactionException: Error performing insert: java.lang.String cannot be cast to com.vividsolutions.jts.geom.Geometry
at org.geoserver.wfs.InsertElementHandler.execute(InsertElementHandler.java:205)
at org.geoserver.wfs.Transaction.execute(Transaction.java:333)
at org.geoserver.wfs.Transaction.transaction(Transaction.java:108)
at org.geoserver.wfs.DefaultWebFeatureService.transaction(DefaultWebFeatureService.java:162)
….

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to com.vividsolutions.jts.geom.Geometry
at org.geotools.jdbc.JDBCDataStore.insertSQL(JDBCDataStore.java:3445)
at org.geotools.jdbc.JDBCDataStore.insert(JDBCDataStore.java:1410)

….

The request is generated by OpenLayers, so I guess that coordinates are right.
Can anyone please help? I’m stuck with investigating on it.

I have a similar problem.
My geometry is of type Linestring and the SRS is epsg:4326

PostgreSQL-8.4.8, PostGIS-1.5.2

I'm including the DEBUG messages

...
2011-12-14 12:57:29,025 INFO [org.geoserver.wfs] -
Request: getServiceInfo
2011-12-14 12:57:29,326 DEBUG [org.geoserver.wfs] - Locating FeatureSource
uri:'http://localhost/test1’ name:'table1'
2011-12-14 12:57:29,326 DEBUG [org.geoserver.wfs] - located FeatureType w/
typeRef 'test1:table1' and elementName '{http://localhost/test1\}table1'
2011-12-14 12:57:29,326 DEBUG [org.geoserver.wfs] - Transasction
Insert:net.opengis.wfs.impl.InsertElementTypeImpl@anonymised.com (feature:
[SimpleFeatureImpl:table1=[SimpleFeatureImpl.Attribute: fid<fid
id=fid--77e35c98_1343b534f7f_-7ff6>=0, SimpleFeatureImpl.Attribute:
wkb_geometry<wkb_geometry id=fid--77e35c98_1343b534f7f_-7ff6>=]], handle:
null, idgen: <unset>, inputFormat: <unset>, srsName: null)
2011-12-14 12:57:29,326 DEBUG [org.geoserver.wfs] - Use featureValidation to
check contents of insert
2011-12-14 12:57:29,326 ERROR [org.geoserver.wfs] - Transaction failed
org.geoserver.wfs.WFSTransactionException: Error performing insert:
java.lang.String cannot be cast to com.vividsolutions.jts.geom.Geometry
  at
org.geoserver.wfs.InsertElementHandler.execute(InsertElementHandler.java:202)
  at org.geoserver.wfs.Transac...

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/WFS-error-performing-insert-java-lang-String-cannot-be-cast-to-com-vividsolutions-jts-geom-Geometry-tp7091003p7092704.html
Sent from the GeoServer - User mailing list archive at Nabble.com.

Nikolay,

I found the cause of my problem.
The DrawFeature control is creating MultiLinestring geometries while the layer needs a LineString. Setting the geometryType if the vector layer didn’t work. So I implemented a small function for the onFeatureInsert event in the layer definition to make it LineString.

// geometryType: “OpenLayers.Geometry.LineString”,
onFeatureInsert: function(feature){
feature.geometry = feature.geometry.components[0];
},

I should probably do some type checking before I assign the first geometry, but this is working for now.

On Wed, Dec 14, 2011 at 1:25 PM, chaitanya_ch <chaitanya.ch@anonymised.com> wrote:

I have a similar problem.
My geometry is of type Linestring and the SRS is epsg:4326

PostgreSQL-8.4.8, PostGIS-1.5.2

I’m including the DEBUG messages


2011-12-14 12:57:29,025 INFO [org.geoserver.wfs] -
Request: getServiceInfo
2011-12-14 12:57:29,326 DEBUG [org.geoserver.wfs] - Locating FeatureSource
uri:‘http://localhost/test1’ name:‘table1’
2011-12-14 12:57:29,326 DEBUG [org.geoserver.wfs] - located FeatureType w/
typeRef ‘test1:table1’ and elementName ‘{http://localhost/test1}table1
2011-12-14 12:57:29,326 DEBUG [org.geoserver.wfs] - Transasction
Insert:net.opengis.wfs.impl.InsertElementTypeImpl@anonymised.com (feature:
[SimpleFeatureImpl:table1=[SimpleFeatureImpl.Attribute: fid=0, SimpleFeatureImpl.Attribute:
wkb_geometry<wkb_geometry id=fid–77e35c98_1343b534f7f_-7ff6>=]], handle:
null, idgen: , inputFormat: , srsName: null)
2011-12-14 12:57:29,326 DEBUG [org.geoserver.wfs] - Use featureValidation to
check contents of insert
2011-12-14 12:57:29,326 ERROR [org.geoserver.wfs] - Transaction failed
org.geoserver.wfs.WFSTransactionException: Error performing insert:
java.lang.String cannot be cast to com.vividsolutions.jts.geom.Geometry
at
org.geoserver.wfs.InsertElementHandler.execute(InsertElementHandler.java:202)
at org.geoserver.wfs.Transac…


View this message in context: http://osgeo-org.1803224.n2.nabble.com/WFS-error-performing-insert-java-lang-String-cannot-be-cast-to-com-vividsolutions-jts-geom-Geometry-tp7091003p7092704.html
Sent from the GeoServer - User mailing list archive at Nabble.com.


Cloud Computing - Latest Buzzword or a Glimpse of the Future?
This paper surveys cloud computing today: What are the benefits?
Why are businesses embracing it? What are its payoffs and pitfalls?
http://www.accelacomm.com/jaw/sdnl/114/51425149/


Geoserver-users mailing list
Geoserver-users@anonymised.comsts.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users


Best regards,
Chaitanya kumar CH.

+91-9494447584
17.2416N 80.1426E

Hola Nick :

/Hi Nick : /

El mensaje de error que te bota el firebug *"Error performing insert:
java.lang.String cannot be cast to com.vividsolutions.jts.geom.Geometry"* se
debe a que el geoserver o las funciones del geoserver para el servicio wfs
solo reconoce a los tipo de datos (TYPE) *POLYGON*, *LINESTRING *y *POINT*
de la tabla geometry_columns. Si deseas poder dibujar todo tipo de
geometría, deberás crear una capa *"OpenLayers.Layer.Vector"* para cada tipo
de geometría.

/The error message you boot the firebug * "Error performing insert:
java.lang.String can not be cast to com.vividsolutions.jts.geom.Geometry" *
is that the geoserver or functions of geoserver wFS service for only
recognizes the data type (TYPE) * POLYGON *, * LINESTRING * and * POINT *
GEOMETRY_COLUMNS table. If you want to draw all kinds of geometry, you must
create a layer * "OpenLayers.Layer.Vector" * for each type of geometry./

Saludos.

/Regards./

--
View this message in context: http://osgeo-org.1560.n6.nabble.com/WFS-error-performing-insert-java-lang-String-cannot-be-cast-to-com-vividsolutions-jts-geom-Geometry-tp3787417p4975204.html
Sent from the GeoServer - User mailing list archive at Nabble.com.

Hi Chaitanya,
I would like to have some more information about your solution, in the case
of a message error occuring because of an inappropriate geometryType.
You wrote :

chaitanya_ch wrote

// geometryType: "OpenLayers.Geometry.LineString",
    onFeatureInsert: function(feature){
        feature.geometry = feature.geometry.components[0];
    },

How do you insert it ?
Something like this ?
var wfs = new OpenLayers.Layer.Vector("wfs", {
            strategies: [new OpenLayers.Strategy.Fixed(), saveStrategy],
                protocol: new OpenLayers.Protocol.WFS({
                    url: ".../geoserver/wfs",
                    featureType: "wfs",
          featurePrefix: "1",
          geometryName: "the_geom"
        }),
        styleMap: selectionStyleWFS,
                rendererOptions: {zIndexing: true},
        renderers: renderer,
        projection: "EPSG:2100",
        geometryType: "OpenLayers.Geometry.LineString",
        onFeatureInsert: function(feature){
          feature.geometry = feature.geometry.components[0];
        },
      }
Because it's not working for me. Thank you for your help.

--
View this message in context: http://osgeo-org.1560.n6.nabble.com/WFS-error-performing-insert-java-lang-String-cannot-be-cast-to-com-vividsolutions-jts-geom-Geometry-tp3787417p4977928.html
Sent from the GeoServer - User mailing list archive at Nabble.com.

Hi, I also encountered the same problem,but my postgre geometryType is
multilinestring, openlayers post a lineString to geoserser,So, I set the
"multi" value of DrawFeature Control as follow:
new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, {
                displayClass: 'olControlDrawFeaturePath',
                handlerOptions: {citeCompliant:
this.citeCompliant,multi:true}
            });

My problem is solved;

Can find the way to set automatically the value by the schema?

--
View this message in context: http://osgeo-org.1560.x6.nabble.com/WFS-error-performing-insert-java-lang-String-cannot-be-cast-to-com-vividsolutions-jts-geom-Geometry-tp3787417p5093704.html
Sent from the GeoServer - User mailing list archive at Nabble.com.