4

I need to convert a Google Maps polygon object (can has multi paths and holes) to wkt string (multipolygon) at client. Then i'll able to save polygon as geography in Sql Server 2012.

I tried Wicket (https://github.com/arthur-e/Wicket) but it has a bug converting multipolygons.

Is there any ready to use library? Any ideas, please?

Thanks.

1
  • Can you share the code of the object or a sample object?
    – johanvdw
    Commented Jun 17, 2013 at 13:47

2 Answers 2

2

I just enabled multipolygon support (Arrays of google.maps.Polygon instances) in Wicket, version 1.0. Clone the "master" branch or download the 1.0 release.

1

If you can iterate the rings and holes you can do this yourself. Format is pretty simple. Pseudocode:

emit 'MULTIPOLYGON('

for each ring

  if it's not the first ring emit ','

  emit '(' 

  emit '('


    for each point in ring
     if it's not the first point emit ','

     emit X

     emit ' '

     emit Y

     end point loop
  emit ')'


  for each hole in ring

   emit ',('

     for each point in hole

      if it's not the first point emit ','

      emit X

      emit ' '

      emit Y

   end point loop

  emit ')'

  end hole loop

emit ')'

end ring loop

emit ')'
7
  • I'm curious why the thumbs down. I don't believe there is any error, is there a disliking for pseudocode in general in this forum? Commented Jun 17, 2013 at 14:37
  • 1
    thanks for the answer, but there is no way to get rings and it's inner rings from google maps polygon object. it contains all paths but no containment information. Commented Jun 17, 2013 at 17:30
  • -1 because the pseudo-code cannot be applied with google map api Commented Jun 17, 2013 at 19:19
  • Ah. Bummer. Appreciate the explanation. Commented Jun 18, 2013 at 17:50
  • Actually, it supports GetPaths and from this stackoverflow.com/questions/7494474/… it appears that direction of rotation determines holes. However, by the time you have to compute order of rotation the code is not so trivial. Commented Jun 18, 2013 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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