[postgis-users] adding multipolygons

Nicolas Ribot nicky666 at gmail.com
Fri May 25 00:27:53 PDT 2007


> 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



More information about the postgis-users mailing list