unity-game-enginegisarcgisesri

How to Spatial filter 3D object areas in Unity using ArcGIS Maps SDK for Unity?


I'm having an issue, I don't quite understand their C# API about Spatial filter.

Link to C# API

This is what I managed to think of and found in forums:

    void CreatePolygons()
    {
        ArcGISPolygonBuilder pb = new ArcGISPolygonBuilder(ArcGISSpatialReference.WGS84());

        pb.AddPoint(21.130116, 55.663546, 1000);
        pb.AddPoint(21.148544, 55.664257, 1000);
        pb.AddPoint(21.180174, 55.645800, 1000);
        pb.AddPoint(21.131820, 55.639522, 1000);

        ArcGISPolygon polygon = pb.ToGeometry() as ArcGISPolygon;

        // Create a list to hold polygons
        ArcGISCollection<ArcGISPolygon> polygons = new ArcGISCollection<ArcGISPolygon>();
        polygons.Add(polygon);

        ArcGISSpatialFeatureFilter filter = new ArcGISSpatialFeatureFilter(polygons, ArcGISSpatialFeatureFilterSpatialRelationship.Disjoint);

        //buildingLayer.FeatureFilter = filter;

        Debug.Log("Drawed");
    }

I don't know how to assign to layer. Because I made my map using their UI, not with code.


Solution

  • I managed to found the answer which worked for me.

        void CreateSpatialFilter(ArcGIS3DObjectSceneLayer layer)
    {
        ArcGISPolygonBuilder pb = new ArcGISPolygonBuilder(ArcGISSpatialReference.WGS84());
        ArcGISPoint point1 = new ArcGISPoint(-73.99980079704791, 40.70807170346215, ArcGISSpatialReference.WGS84());
        ArcGISPoint point2 = new ArcGISPoint(-74.0133251342158, 40.70044995342926, ArcGISSpatialReference.WGS84());
        ArcGISPoint point3 = new ArcGISPoint(-74.01934729189811, 40.705750450644196, ArcGISSpatialReference.WGS84());
        ArcGISPoint point4 = new ArcGISPoint(-74.01291685233905, 40.71700777141413, ArcGISSpatialReference.WGS84());
    
        pb.AddPoint(point1);
        pb.AddPoint(point2);
        pb.AddPoint(point3);
        pb.AddPoint(point4);
    
        ArcGISPolygon polygon = (ArcGISPolygon)pb.ToGeometry();
        ArcGISCollection<ArcGISPolygon> polygons = new ArcGISCollection<ArcGISPolygon>();
        polygons.Add(polygon);
    
        ArcGISSpatialFeatureFilter filter = new ArcGISSpatialFeatureFilter(polygons, ArcGISSpatialFeatureFilterSpatialRelationship.Disjoint);
        layer.FeatureFilter = filter;
    }