I would like to define create a GeoJSON bounding box using SQL Server's EnvelopeAggregate function, embedded in an ogr2ogr command. I have the following command:

ogr2ogr -f GeoJSON envelope.json "MSSQL:server=SERVERNAME;database=DBNAME;trusted_connection=ye
s;" -sql "select TR, Geometry::EnvelopeAggregate(Shape) as Shape from gis.SampleTable where TR = '000280965
8' group by TR" "-s_srs" "+proj=tpeqd +lat_1=49 +lon_1=-110 +lat_2=49 +lon_2=-77 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no
_defs", "-t_srs", "epsg:4326"

The resulting GeoJSON file contains null geometry, despite the same SQL query working as expected in SQL Server Management Studio:

"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },

"features": [
{ "type": "Feature", "properties": { "TR": "0002809658", "Shape":  "00000000010405000000009899992166D5408061325554EB21C100E00B936336E0408061..."     }, "geometry": null }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.