1

I am trying to combine thousands of rectangles into one polygon using DbGeography. For testing, I'm starting with just two rectangles (because the thousands failed with a fullglobe result). When I use the union method of DbGeography, it returns a polygon with one rectangle subtracted from the other instead of combining them. I tried the same process with SQLGeography and got the same result. Can anyone see what I'm doing wrong? Or maybe I misunderstand the Union method?

Two separate rectangles showing overlap:

enter image description here

Resulting polygon after union:

enter image description here

Code (geog1 is upper left rectangle, geog2 is lower right):

DbGeography geogUnion = geog1;     
geogUnion = geogUnion.Union(geog2);

And here are the values for the polygons I am merging and the resulting polygon:

geog1: POLYGON ((-114.964104 36.008963, -114.964104 36.005183, -114.958248 36.005183, -114.958248 36.008963, -114.964104 36.008963))

geog2: POLYGON ((-114.957387 36.006575, -114.957387 36.000681, -114.9608 36.000681, -114.9608 36.006575, -114.957387 36.006575))

geogUnion: POLYGON ((-114.957387 36.000681, -114.9608 36.000681, -114.96080000000012 36.005183034992221, -114.958248 36.005183, -114.95824799999998 36.00657500911889, -114.957387 36.006575, -114.957387 36.000681))
Mikecito
  • 2,053
  • 11
  • 17

1 Answers1

0

I figured this out after a lot of testing. The rectangles were drawn in different orientations, meaning one was clockwise and the other was counterclockwise. This happened because the data I was drawing from was inconsistent in our database defining the rectangles.

Once I normalized the data by orienting both rectangles in the same manner, it behaved as expected. I hope this helps someone else with a similar issue.

Mikecito
  • 2,053
  • 11
  • 17