[CSHARP-2464] There is no way to specify the CRS using the Mongo C# driver Created: 26/Dec/18  Updated: 08/Jan/19  Resolved: 08/Jan/19

Status: Closed
Project: C# Driver
Component/s: Read Operations
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ian Hannah Assignee: Kelsey Schubert
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-38765 Geo within query requires custom crs ... Closed

 Description   

I am using the Within query and I need to specify the CRS so that it works for "big polygons" so I have tired this:
 
            GeoJsonCoordinateReferenceSystem crs = new GeoJsonNamedCoordinateReferenceSystem("urn:x-mongodb:crs:strictwinding:EPSG:4326");
            GeoJsonObjectArgs<GeoJson2DGeographicCoordinates> args = new GeoJsonObjectArgs<GeoJson2DGeographicCoordinates>();
            args.CoordinateReferenceSystem = crs;
 
and use it in this call:
 
           IMongoQuery geoQuery = Query.Within<GeoJson2DGeographicCoordinates>(MongoItem.PolygonRegionProperty, new GeoJsonPolygon<GeoJson2DGeographicCoordinates>(args, new GeoJsonPolygonCoordinates<GeoJson2DGeographicCoordinates>(new GeoJsonLinearRingCoordinates<GeoJson2DGeographicCoordinates>(polygon.Select(i => new GeoJson2DGeographicCoordinates(i.Longitude, i.Latitude))))));
 
but this returns this:
 
"$geometry" : { "type" : "Polygon", "crs" : { "type" : "name", "properties" :

{ "name" : "urn:x-mongodb:crs:strictwinding:EPSG:4326" }

}, "coordinates" : [[[-34.353119999999997, -50.140853], [-34.353119999999997, 76.184997999999993], [146.24300500000001, 76.184997999999993], [146.24300500000001, -50.140853], [-34.353119999999997, -50.140853]]] } } }
 
whereas I need this:
 
        "$geometry" :{ 
            "type" : "Polygon", "coordinates" : [[[-34.353119999999997, -50.140853], [146.24300500000001, -50.140853], [146.24300500000001, 
 
76.184997999999993], [-34.353119999999997, 76.184997999999993], [-34.353119999999997, -50.140853]]],    
            crs:

{                 type: "name",                 properties: \{ name: "urn:x-mongodb:crs:strictwinding:EPSG:4326" }

            } 
        }
 
i.e. the crs setting is in the wrong place and I cannot work out how to get it in the correct place. There is no way to set the CRS correctly using the within query.



 Comments   
Comment by Kelsey Schubert [ 08/Jan/19 ]

Thanks for the update, I'm glad you were able to figure out what the issue was.

Comment by Ian Hannah [ 27/Dec/18 ]

The query does work. This did not work because the coordinates were in clockwise order rather than counter-clockwise as is required for an inclusive area so this now works.

The CRS can therefore be specified using the driver so this issue can be closed.

Comment by Ian Hannah [ 27/Dec/18 ]

Please note that the CRS can be specified using the C# driver BUT the query does not work when it is using the inclusive area. 

Can you please confirm that this is a bug? Can you please give me an update on exactly what the problem is?

Comment by Ian Hannah [ 26/Dec/18 ]

I have got the issue down to this query:

db.items.find({"GeoPol":{
"$within" : {
"$geometry" :{
"type" : "Polygon", "coordinates" : [[[-34.353119999999997, -50.140853], [-34.353119999999997, 76.184997999999993], [146.24300500000001,
76.184997999999993], [146.24300500000001, -50.140853], [-34.353119999999997, -50.140853]]],
"crs":

{ "type": "name", "properties": \{ "name": "urn:x-mongodb:crs:strictwinding:EPSG:4326" }

}
}
}
}
})

The coordinates have been specified in a counter clockwise order which means that, together with the crs, this is an inclusive area.

The coordinates of the polygon in the database is defined as:

0.026856601145655,53.3536401702337;-0.018187415636542,53.3543968971421;-0.016935805565727,53.381347118852;-0.01651815359378,53.3903304943447;-0.001490628678547,53.390079813912;-0.001911439808241,53.3810965200027;0.028136611683245,53.3805896527841;0.026856601145655,53.3536401702337

This is well inside the polygon in the query above so why is it not being matched?

Comment by Ian Hannah [ 26/Dec/18 ]

This does appear to work but it seems to depend on the order of the coordinates i.e. they must be clockwise or counter-clockwise. Can you please confirm? 

Generated at Wed Feb 07 21:42:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.