[postgis-users] adding multipolygons

Malm Paul paul.malm at saabgroup.com
Fri May 25 01:01:39 PDT 2007


Hi,
I've tried this before, but it did not work.

Code:
PreparedStatement stmt = con.prepareStatement("insert into " +
"\"public\".\"" + sentence[0] + "\" (the_geom) " +
"values(geometryFromText(?, -1))");

stmt.setString(1, "\'MULTIPOLYGON(" + lon1 + " " + lat1 + ", " + lon2 +
" " + lat2 + ", " + lon3 + " " + lat3 + ", " + lon1 + " " + lat1  +
")\'");
stmt.executeUpdate();



But then I got the following Error:

org.postgresql.util.PSQLException: ERROR: Invalid OGC WKT (does not
start with P,L,M or G)

This is the prepared statement in the debugger:

insert into "public"."depareTriang" (the_geom)
values(geometryFromText('MULTIPOLYGON(16.9991608 58.1510817, 16.9969661
58.152005, 16.9992367 58.1512597, 16.9991608 58.1510817)', -1))

Kind regards,
Paul




-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of
Nicolas Ribot
Sent: den 25 maj 2007 09:28
To: PostGIS Users Discussion
Subject: Re: [postgis-users] adding multipolygons

> Hi, list
>
> I'm trying to add some polygons in a post_Gis database as
multipolygons.
>
>
> The polygons shall be stored via a java application.This is the code:
>
> PreparedStatement stmt = con.prepareStatement("insert into " + 
> "\"public\".\"" + sentence[0] + "\" (the_geom) " + 
> "values(geometryFromText(?, -1))");
>
> stmt.setString(1, "MULTIPOLYGON(" + lon1 + " " + lat1 + ", " + lon2 + 
> " " +
> lat2 + ", " + lon3 + " " + lat3 + ", " + lon1 + " " + lat1  + ")");
>
> stmt.executeUpdate();
>
>
> But I'm getting the following error code:
> org.postgresql.util.PSQLException: ERROR: parse error - invalid 
> geometry
>
>
> In the debugger I can see the prepared statement:
> insert into "public"."depareTriang" (the_geom)
> values(geometryFromText(MULTIPOLYGON(16.9992367 58.1512597,
> 16.9969661 58.1513289, 16.9994428 58.1512597, 16.9992367 58.1512597), 
> -1))
>
> By the way
> do I have to close the polygon by ending with the start point?
>

Your multipolygon syntax is wrong (see:
http://postgis.refractions.net/docs/ch04.html#id2612912) and you have to
quote it as geometryFromtext is expecting a text:

geometryFromText('MULTIPOLYGON((....))', -1)

Yes, start and end points must be the same.

Nicolas
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



More information about the postgis-users mailing list