smindel / silverstripe-gis

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

WithinGeo filter doesn't seem to work #16

Closed phptek closed 5 years ago

phptek commented 5 years ago

To reproduce (using v1.1.3)

        $coords = (array) $request->postVar('coords');
        $srid = Config::inst()->get(GIS::class, 'default_srid');
        $records = PlanPage::get()->filter([
            'Location:WithinGeo' => GIS::array_to_ewkt($coords, $srid, true),
        ]);

Note: As discussed, there should prob be a unit-test to cover the WithinGeo filter :-)

[UPDATE]

I was partly being an idiot, in that I was relying too hard on expected behviour. In a standard SilverStripe FormField subclass, changing the value, re-renders the "Publish" button, as SilverStripe detects that something has changed. It is this that isn't happening for the MapField. SilverStripe simply wasn't recognising that a change had ocurred. Once I made a change to a different field, the "Publish" button highlighted itself, and publishing wrote the right Geometry string to the xx_Live table.

phptek commented 5 years ago

A simplified query that returns the expected single row:

SELECT * FROM "SomePage" WHERE (ST_Intersects(ST_GeomFromText('POLYGON((174.78122057099 -41.2900367890677,174.781886102042 -41.2902302628832,174.782658976811 -41.2896982085099,174.78289513299 -41.2898271917867,174.782701914298 -41.2902947540276,174.782852195503 -41.2904721043458,174.782487226862 -41.2910202750086,174.781113227272 -41.2906655768704,174.78122057099 -41.2900367890677))', 4326),"SomePage"."Location"))

One that doesn't work (containing multple SIlverStripe JOIN's)

SELECT DISTINCT "SiteTree_Live"."ClassName", "SiteTree_Live"."LastEdited", "SiteTree_Live"."Created", "SiteTree_Live"."CanViewType", "SiteTree_Live"."CanEditType", "SiteTree_Live"."Version", "SiteTree_Live"."URLSegment", "SiteTree_Live"."Title", "SiteTree_Live"."MenuTitle", "SiteTree_Live"."Content", "SiteTree_Live"."MetaDescription", "SiteTree_Live"."ExtraMeta", "SiteTree_Live"."ShowInMenus", "SiteTree_Live"."ShowInSearch", "SiteTree_Live"."Sort", "SiteTree_Live"."HasBrokenFile", "SiteTree_Live"."HasBrokenLink", "SiteTree_Live"."ReportClass", "SiteTree_Live"."ParentID", "Page_Live"."LandingPageSummary", "Page_Live"."LandingPageSummaryImageID", "SomePage_Live"."Type", "SomePage_Live"."Label", "SomePage_Live"."Address", "SomePage_Live"."Name", "SomePage_Live"."Abstract", ST_AsEWKT("SomePage_Live"."Location") "Location", "SiteTree_Live"."ID", CASE WHEN "SiteTree_Live"."ClassName" IS NOT NULL THEN "SiteTree_Live"."ClassName" ELSE E'SilverStripe\\CMS\\Model\\SiteTree' END AS "RecordClassName" FROM "SiteTree_Live" LEFT JOIN "Page_Live" ON "Page_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "SomePage_Live" ON "SomePage_Live"."ID" = "SiteTree_Live"."ID" WHERE (ST_Intersects(ST_GeomFromText('POLYGON((174.78122057099 -41.2900367890677,174.781886102042 -41.2902302628832,174.782658976811 -41.2896982085099,174.78289513299 -41.2898271917867,174.782701914298 -41.2902947540276,174.782852195503 -41.2904721043458,174.782487226862 -41.2910202750086,174.781113227272 -41.2906655768704,174.78122057099 -41.2900367890677))', 4326),"SomePage_Live"."Location")) ORDER BY "SiteTree_Live"."Sort" ASC
phptek commented 5 years ago

I have traced this back to a failed JOIN. For some reason ,using MapField in updateCMSFields() in a DataExtension on Page, failes to populate the "Location" field on the page's xx_Live table.

smindel commented 5 years ago

Sorry, I can't reproduce this issue. It is working fine for me:

Page.php with Geometry field saved and published successfully using the CMS.