Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Problem: I'm trying to find a way to fix some broken polygon shapes and I'm not sure how I can do this.


Details:

I've got a number of polygons which I basically imported from TIGERLINES a while back.

I transformed them into shape files, then imported them into Sql Server 2008.

In sql server 2008, they look great :) So that suggests that the import more or less worked. Here's the city of Los Angeles :-

enter image description here

But because my poly's have lots of points, i REDUCE them when the map view level is not zoomed in. So in my case, I'm now trying to render out a reduced Los Angeles :-

enter image description here

Awesome!

This is the polys as a Well Known Text format..

MULTIPOLYGON (((-118.37033296865027 33.981437119998084, -118.37005887887605 33.981578692036159, -118.37034101004039 33.981636093563019, -118.37033296865027 33.981437119998084)), ((-118.66815694082851 34.181234948814819, -118.62915309690062 34.14689902389253, -118.56475201393673 34.130168028388276, -118.5992039806748 34.074336925351339, -118.57039497030522 34.069345957209549, -118.56968692628638 33.988811006799452, -118.55134001501617 33.982488918901176, -118.49446792996977 34.050559988837591, -118.44342601159182 34.016625025023124, -118.53748592914029 33.96667393391462, -118.49898897162241 33.916299091437473, -118.43732802504242 33.91651401198633, -118.4580839734636 33.961275936767734, -118.42944687485486 33.916317947202252, -118.4287748805515 33.93096998019935, -118.36821587274666 33.92901995236047, -118.37033296865027 33.981437119998084, -118.38014006025271 33.976370879899918, -118.40620312831412 33.9894040312244, -118.40276798429554 34.003464906235209, -118.44721596021705 33.990835906868767, -118.36957705476188 34.035079980519519, -118.37898513570399 34.01930701338695, -118.35780514530173 33.997145063915781, -118.33148511073327 34.001491938133285, -118.37005887887605 33.981578692036159, -118.3177468750705 33.970922985911365, -118.31338700532739 33.93821409504941, -118.29159591706274 33.959494911587832, -118.29062400107088 33.866332991682327, -118.30914811626086 33.865608026065182, -118.30099998201904 33.757721074150069, -118.33305692619008 33.721861951611757, -118.29415704014427 33.704554033590789, -118.23180307928671 33.71500194765504, -118.24896594980441 33.755902076278147, -118.22066886552763 33.782536959833138, -118.22662214917852 33.829531051866013, -118.23026099256474 33.792772095531092, -118.2565120484562 33.804774040894074, -118.2991459834285 33.797795976339046, -118.29920702986115 33.846318895031622, -118.28155507034047 33.86280202135606, -118.28208595952513 33.923201066885447, -118.23032405030229 33.929000895691168, -118.23399502457268 33.953263926662473, -118.25364008888438 33.943276983800338, -118.25643608790811 33.989497954281944, -118.23791790420275 33.989393059909709, -118.23970793049459 34.014713121327667, -118.19142810960136 34.012760956499392, -118.19262502907846 34.061762066095284, -118.1648349431549 34.062282928139695, -118.15528996126079 34.098672108789643, -118.17799390878898 34.098595067874996, -118.16558689825808 34.125466989766352, -118.18258002511257 34.129185991443848, -118.18392009154192 34.148673011439996, -118.22623088187513 34.149788973944844, -118.25425797615566 34.11876096748162, -118.28169102368197 34.156473098182232, -118.30964606995528 34.1612589323332, -118.34566505636386 34.142366926730304, -118.37031291768209 34.196379107293332, -118.33992999453659 34.206502959021506, -118.33746198396433 34.221312054601036, -118.26687107795063 34.221846086487439, -118.26667204057179 34.250779088440183, -118.2387889442851 34.281588919772553, -118.28669401126965 34.278336948162604, -118.29939493959903 34.293259048809304, -118.35470798399948 34.278848025464875, -118.3857618914668 34.284817020858974, -118.38739588298223 34.298779939448842, -118.4061680961638 34.2859269071303, -118.40520195114632 34.329811005464386, -118.50380990538876 34.337305995327178, -118.54629607559784 34.317332026288142, -118.5408208870528 34.2988139356695, -118.58853302357504 34.303219086876425, -118.59620799129411 34.274520945225589, -118.63346111715893 34.269525030054467, -118.63072510622223 34.2377719451453, -118.65873494162602 34.224578011901244, -118.66815694082851 34.181234948814819), (-118.46636404681055 34.0590670662609, -118.45468090186466 34.066799004274742, -118.44817495570614 34.049578023438457, -118.46636404681055 34.0590670662609), (-118.42624590643248 34.083052060665487, -118.39585612350398 34.112414074702421, -118.39584401878872 34.091055026539784, -118.34338194827956 34.09432806847537, -118.37695090866218 34.088630040183155, -118.3702939050842 34.0801689603087, -118.39070402303155 34.072083071358719, -118.37224405760227 34.062199935390908, -118.40602306576152 34.052665897923667, -118.42624590643248 34.083052060665487), (-118.45592304445982 34.284612059955819, -118.43256891423674 34.304687007226292, -118.41566704665274 34.2939320092269, -118.4437338970905 34.273310001969548, -118.45592304445982 34.284612059955819), (-118.3623419482557 34.1386959352159, -118.34569798267972 34.14235601789391, -118.34877496666293 34.131385983468121, -118.3623419482557 34.1386959352159), (-118.46233312716733 33.979751022958048, -118.43225893050703 33.9750159246595, -118.4513010127346 33.964230958845896, -118.46233312716733 33.979751022958048)))

Now, to show the polys on a Google map, I need to extract the data from Sql Server, convert it to a Google Maps format and then display. This works great for .. say .. 95% of polys. The other 5% look .. very very messed up.

Not-Ok Los Angeles:-

enter image description here

So I'm guessing you're going to suggest -> check if there's any bugs in the code? Can we see the code? It's got something do to with the code!

Well, here is the sample code library I've put up into Codeplex. It includes a unit test with the binary data of the shape. (SELECT MediumReducedBoundary.STAsBinary() FROM Table WHERE Id=1)

I then Parse this byte[] .. and display it on a Google Map.

My transformation code returns TWO polygons, not one.

This is what my Json looks like .. notice how it has two polygons now?

The client side javascript code is found here. This is where i decode my json and try and manually render this onto a google map.

I'm hoping there might be a way/program that can read in my json result and tell me if this data is bad (I converted it, incorrectly). Or if someone can see where I've converted the WKT incorrectly into my google formatted JSON?

share|improve this question
    
FWIW, the multipolygon is valid/simple, so there shouldn't be a problem with that. Secondly, yes there are two objects. The first polygon is a tiny triangle at POINT (-118.37024428585559 33.981550635199085), which is interesting, but I don't think it is the cause of the issue. –  Mike T Nov 10 '11 at 8:17
    
So would you suggest that the error could be how Sql Server 2008 'reduced' this poly? –  Pure.Krome Nov 10 '11 at 8:21
    
nah, the multipolygon looks good, so I think the issue is with the client/javascript .. but that's were I get lost –  Mike T Nov 10 '11 at 8:30
    
Can u display that WKT in another GIS application to see if it renders it nicely, there? –  Pure.Krome Nov 10 '11 at 8:37
    
Yeah, the WKT renders in JTS TestBuilder the same as your 2nd image after REDUCE, and passes valid/simple tests. I can't figure out how to validate the json, however. –  Mike T Nov 10 '11 at 8:43
show 4 more comments

2 Answers

up vote 3 down vote accepted

Polygons are rendered in Google Maps API using Canvas, which uses a zero-winding fill rule. To show a hole, you'll need to define the hole using the opposite winding to the outer path.

share|improve this answer
    
Hi Broady! thanks heaps for jumping in here and replying! Really appreciate it :) Any chance you could provide a link or two, too some examples of this, please? I'll then send a slab of beer to your office in thanks :) Cheers mate! –  Pure.Krome Nov 23 '11 at 23:05
    
Sure - here's a good one of a donut: geocodezip.com/v3_polygon_example_donut.html –  broady Dec 5 '11 at 2:52
    
cheers for the link :) but I can't right-click to see how it was done :( –  Pure.Krome Dec 5 '11 at 5:33
    
Just hit view source! –  broady Dec 5 '11 at 11:39
add comment

To me it looks like the Google Maps version does not understand the holes in the same way as your original source. You need to find out how holes are expected to be defined in Google Maps.

It might be that you are missing some points that needs to close each hole-polygon before going to the next. I don't know how Google Maps defines this, it's just a guess...

share|improve this answer
    
Hmm .. this sounds pretty accurate. Hmmmm .. looks like I need to find a Google Map javascript expert? Anyone around here, know of one? –  Pure.Krome Nov 14 '11 at 23:42
    
@Pure.Krome: I think not necessarily a Javascript expert, but someone who knows the Google Maps data model. –  awe Nov 15 '11 at 7:10
    
ahh .. good point. That might make it even harder to find ... :~( –  Pure.Krome Nov 15 '11 at 8:22
    
You need to find a json API reference that describes how to define polygons with holes. It might be called multipolygons to support holes. –  awe Nov 15 '11 at 9:16
    
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.