On Thu, Jun 14, 2012 at 5:56 AM, Tom Dalling <
tom.d...@gmail.com> wrote:
> Hi,
>
> I'm having trouble with the SRID when inserting points into
> Postgres/PostGIS. I'm getting this error from Postgres:
>
> ERROR: new row for relation "occurrences" violates check constraint
> "enforce_srid_location"
>
>
> This is the SQL causing the error, straight from the Postgres logs:
>
> INSERT INTO occurrences (location, rating, species_id, source_id,
> source_rating)
> VALUES (E'POINT (2.0000000000000000 1.0000000000000000)', E'invalid', 209,
> 100, E'invalid')
> RETURNING
occurrences.id
>
>
> This is the Python code that inserts the row:
>
>
> p = shapely.geometry.Point(occ.coord.longi, occ.coord.lati)
> location = WKTSpatialElement(shapely.wkt.dumps(p), 4326)
>
> db.occurrences.insert().\
>
> returning(
db.occurrences.c.id).\
>
> execute(
>
> location=location,
>
> source_rating=rating,
>
> rating=rating,
>
> species_id=species_id,
>
> source_id=self.source_row_id
>
> ).scalar()
>
>
> I tested out some inserts in psql, and it seems the error is triggered if
> the SRID isn't set on the point. For instance this will trigger the error:
>
> ST_GeomFromText('POINT(-71.064544 42.28787)')
>
>
> But this works just fine:
>
> ST_GeomFromText('POINT(-71.064544 42.28787)', 4326)
>
>
> My guess is that the SRID isn't making it into the SQL, but I can't work out
> why. Any ideas?
I'd like to reproduce that. It would be ideal if you could come up
with a self-contained test-case, like this:
<
https://github.com/geoalchemy/geoalchemy/issues/17#issuecomment-6069375>.
I could do it myself, but I won't be able to do it until a few weeks.
Thanks,
--
Eric