Creating an MKPolygon from the intersection of 2 or more MKPolygon objects
Does anyone kn开发者_开发技巧ow if this is possible. I'm trying to create a pretty complex polygon, and was wondering if there's any way to take 2 or more objects that are MKPolygon's and create a new MKPolygon from it.
Thanks!
MKPolygon and it's ancestors are pretty simplistic. About the most you can do with ease is to make a large mkpolygon and start filling in inner polygon "holes" or rings to create more complex shapes.
That being said, if you're talking about real geometric math, unions, intersections, and more complex functions, you may want to use a geo-specific framework (or treat your lat/long as x/y double floats and just use regular textbook geometry functions to build 2d polys)
Michael Weisman has a good geo/GIS lib called ShapeKit, geared towards iOS specifically. It acts as a front end to GEOS and PROJ.4, two extremely powerful libraries. This is probably your best, safest bet.
Another option that you may want to explore, if you don't have to compute the polygons on the device, ... Serve up your polygons from a GIS powered database server. I have a few modifications to shapekit that let you import binary WKB polygons from mysql or elsewhere ... You've got fast powerful functions there to offload processing power if needed. Or you could even bring them straight from a Esri shapefile to iOS if that's where your coming from... I did a proof of concept of that on GitHub too.
I have written a solution for this. Check out MKPolygon-GPC. Its an Objective-C wrapper around Alan's the GPC lib.
精彩评论