Skip to content

Commit c78ca62

Browse files
committed
Added support for bounding box spatial reference per issue #8
1 parent e69028b commit c78ca62

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

GeoJSONSOE/GeoJSONSOE.cs

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private RestResource CreateRestSchema()
114114
RestResource rootRes = new RestResource(soe_name, false, RootResHandler);
115115

116116
RestOperation geoJsonOper = new RestOperation("GeoJSON",
117-
new string[] { "query", "layer","bbox" },
117+
new string[] { "query", "layer","bbox", "bboxSR" },
118118
new string[] { "geojson" },
119119
ExportGeoJsonHandler);
120120

@@ -231,9 +231,11 @@ private byte[] ExportGeoJsonHandler(NameValueCollection boundVariables,
231231
responseProperties = "{\"Content-Type\" : \"application/json\"}"; ;
232232
bool applyQuery = true;
233233
bool useBbox = true;
234+
bool useBboxSR = true;
234235
string retval = "";
235236
string whereClause;
236237
string boxClause;
238+
int bboxSRID = 0;
237239
IPolygon queryGeom = null;
238240
Helpers helper = new Helpers();
239241
bool found = operationInput.TryGetString("query", out whereClause);
@@ -243,6 +245,24 @@ private byte[] ExportGeoJsonHandler(NameValueCollection boundVariables,
243245
applyQuery = false;
244246
}
245247

248+
string ssrid;
249+
found = operationInput.TryGetString("bboxSR", out ssrid);
250+
if (!found || string.IsNullOrEmpty(ssrid))
251+
{
252+
//then no definition query
253+
useBboxSR = false;
254+
}
255+
else
256+
{
257+
int srid;
258+
bool valid = int.TryParse(ssrid, out srid);
259+
if (valid)
260+
{
261+
bboxSRID = srid;
262+
}
263+
else { useBboxSR = false; }
264+
}
265+
246266
found = operationInput.TryGetString("bbox", out boxClause);
247267
if (!found || string.IsNullOrEmpty(boxClause))
248268
{
@@ -265,14 +285,31 @@ private byte[] ExportGeoJsonHandler(NameValueCollection boundVariables,
265285

266286
if (bxmin && bymin && bxmax && bymax)
267287
{
268-
queryGeom = new Polygon() as IPolygon;
269-
IPointCollection coll = queryGeom as IPointCollection;
270-
coll.AddPoint(new Point() { X = xmin, Y = ymin, SpatialReference = helper.getWGS84() });
271-
coll.AddPoint(new Point() { X = xmin, Y = ymax, SpatialReference = helper.getWGS84() });
272-
coll.AddPoint(new Point() { X = xmax, Y = ymax, SpatialReference = helper.getWGS84() });
273-
coll.AddPoint(new Point() { X = xmax, Y = ymin, SpatialReference = helper.getWGS84() });
274-
coll.AddPoint(new Point() { X = xmin, Y = ymin, SpatialReference = helper.getWGS84() });
275-
queryGeom.SpatialReference = helper.getWGS84();
288+
ISpatialReference sr = null;
289+
if (useBboxSR)
290+
{
291+
sr = helper.GetSpatialReference(bboxSRID);
292+
if (sr == null)
293+
{
294+
//erroneous srid, ignore bounding box
295+
useBbox = false;
296+
}
297+
}
298+
else
299+
{
300+
sr = helper.getWGS84();
301+
}
302+
if (useBbox)
303+
{
304+
queryGeom = new Polygon() as IPolygon;
305+
IPointCollection coll = queryGeom as IPointCollection;
306+
coll.AddPoint(new Point() { X = xmin, Y = ymin, SpatialReference = sr });
307+
coll.AddPoint(new Point() { X = xmin, Y = ymax, SpatialReference = sr });
308+
coll.AddPoint(new Point() { X = xmax, Y = ymax, SpatialReference = sr });
309+
coll.AddPoint(new Point() { X = xmax, Y = ymin, SpatialReference = sr });
310+
coll.AddPoint(new Point() { X = xmin, Y = ymin, SpatialReference = sr });
311+
queryGeom.SpatialReference = sr;
312+
}
276313
}
277314
else
278315
{

GeoJSONSOE/Helpers.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ public ISpatialReference GetSpatialReference(ESRI.ArcGIS.Geometry.esriSRGeoCSTyp
8080
{
8181
return null;
8282
}
83+
}
84+
85+
public ISpatialReference GetSpatialReference(int FactoryCode)
86+
{
87+
ISpatialReferenceFactory2 oSpatialReferenceFactory;
88+
ISpatialReference oCS;
89+
try
90+
{
91+
Type t = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
92+
oSpatialReferenceFactory = (ISpatialReferenceFactory2)Activator.CreateInstance(t);
93+
oCS = oSpatialReferenceFactory.CreateSpatialReference(FactoryCode);
94+
return oCS;
95+
}
96+
catch
97+
{
98+
return null;
99+
}
83100
}
84101
}
85102
}

0 commit comments

Comments
 (0)