smindel / silverstripe-gis

Adds support for geographic types.
BSD 3-Clause "New" or "Revised" License
9 stars 5 forks source link

Unable to save Polygon #13

Closed phptek closed 5 years ago

phptek commented 5 years ago

In the CMS, and using the Polygon map-tool to select a multi-point area, I cannot seem to be able to save the record. Using the line-tool works though.

php 7.2 / SilverStripe 4.3 / Postgres 9.5 / Postgis 2.2

The error I get is:

[Emergency] Uncaught SilverStripe\ORM\Connect\DatabaseException: Couldn't run query: UPDATE "PlanRecord" SET "ClassName" = $1, "Location" = ST_GeomFromText($2, $3), "Type" = $4, "Label" = $5, "Address" = $6, "LastEdited" = $7, "Created" = $8, "Version" = $9 WHERE ("ID" = $10) ERROR: geometry contains non-closed rings HINT: "....75690175808978 -41.292060174344435))"
POST /admin/gis/Catalyst-CatPlan-Model-PlanRecord/EditForm/field/Catalyst-CatPlan-Model-PlanRecord/item/new/ItemEditForm/

Line 64 in /vagrant/vendor/silverstripe/framework/src/ORM/Connect/DBConnector.php

I gather this is a PostGIS error. Could the lat/lon be the wrong way around? Is each DB connection using the correct datum/projection?

EDIT:

When creating or editing a record with only 3 points, I get the error:

[Emergency] Uncaught SilverStripe\ORM\Connect\DatabaseException: Couldn't run query: UPDATE "PlanRecord" SET "ClassName" = $1, "Location" = ST_GeomFromText($2, $3), "Type" = $4, "Label" = $5, "Address" = $6, "LastEdited" = $7, "Created" = $8, "Version" = $9 WHERE ("ID" = $10) ERROR: geometry requires more points HINT: "...74.7733789170987 -41.30315140250484))"
POST /admin/gis/Catalyst-CatPlan-Model-PlanRecord/EditForm/field/Catalyst-CatPlan-Model-PlanRecord/item/new/ItemEditForm/

Line 64 in /vagrant/vendor/silverstripe/framework/src/ORM/Connect/DBConnector.php
Source

Which begs the question "What is the minimum no. points that PostGIS will allow"? If there is a minimum. there should probably be some client-side validation or SilverStripe validation to prevent creation of polygons with too few points. But really..If I want to create a triangle, why can't I?!

Here are the steps to reproduce:

phptek commented 5 years ago

I suspect this happens because the final point is not precisely located on top of the first point. Is there a way to "snap" a point onto another in LeafletJS? Meanwhile I have hacked this slightly in my PoC application, by converting "LINESTRING" into "POLYGON" in the custom map JS, which works for my purposes.

smindel commented 5 years ago

Leaflet.draw doesn't close polygons. Fixed in e9bfb3d. Thanks