GIS: Alternative ways of patching gaps in a polygon - gis

I'm working in QGIS but I can also use ArcGIS if there's a solution that works best on there.
I have a shapefile with certain plots of land highlighted and I plan to calculate the distance of features to the borders of these plots. But the plots have the roads and rivers going through them as gaps in the polygons. Like this:
Of course, this messes with the distance calculation I want. The goal is to create new polygons that just the outline only. I have tried the hole function in QGIS. I also tried buffering with dissolving then reversing the buffer. What other methods might work to fill in the gaps?

Related

Google Maps - Polygon with hole and custom background

I want to draw a polygon on Google Maps with a complex background (striped for example). This https://stackoverflow.com/a/15840086/3020903 SO pretty much got me covered on 99% of the cases. It shows how to use custom overlays for this. Problem with this is, it does not support multidimensional coordinate arrays (e.g polygons with holes) and I currently have no idea how to achieve this. I am aware that polygons themselves support custom holes in them, but I need a "striped background" polygon with a hole in it.
One idea was to cut the polygon to multiple ones so that no single one would have a hole in it, but that seems very complex, as my polygons and holes in them might be extremely complex. Even if I could get it working, it will probably break pattern repetition.
Can anyone help me with this?
I got it working after some fiddling with this JsFiddle: http://jsfiddle.net/9gvsq3od/
Basic idea is in combining SVG's fill-rule="evenodd" property with a two dimensional LatLng array and a bit modification to PolyLineFill.prototype.AdjustPoints() to handle the two-dimensional coordinate array.
Heres a working example: http://jsfiddle.net/o4phfL6c/

Calculate length of road in a Polygon

I have this interesting challenge in my work, i have shape files of road networks, and another shape-File containing area boundaries, is there any tool that i can use to get length of roads that lies inside each polygon?
I have access to both QGIS and ArcGIS.
This is probably better asked on gis stackoverflow.
That said, this is a multi-stage problem. I'd suggest something like:
Clip the roads layer by the polygon layer, keeping the polygon id for each road.
Measure the length of the now-clipped roads.
Sum up the road lengths, grouping by the polygon_id
Join the now-measured,-summed-and-clipped roads layer back to the polygon layer.
This will give you what you want.
If you don't know how to use QGIS/ArcGIS, try googling for tutorials (or get work to splurge on training). There are plenty that cover the above functions.

How to merge two shapes from KML files and get coordinates of overlapped area?

There are two KML/KMZ files. As an example one of them has coordinates of black square and another one has coordinates of green square. How can I get coordinates of red square (which is overlapped area)? Looks like ideally this can be scripted or generated using program.
If this can be achieved, then to summarise the goal is to analyse and merge two KML/KMZ files of boundaries and create smaller shapes in one KML/KMZ.
Many thanks
You'll probably want to use software that can perform basic GIS analysis functions. A good free option is QGIS. Load your KML files and then go to the Vector menu and find the Intersect tool.
If you need commandline/script/programatic options, you can look into GDAL and it's OGR Intersection method.

Heat map visualization for discrete values on Google Maps

I'm working on the following scenario: I have a geographical location and I need to create a heat-map visualization of travel times (by car) from that location to anywhere around. I'm planning on using Google Distance Matrix API for getting travel duration. But, since it has a limit on the no of API calls, I need to somehow limit the calls.
My plan, so far, is the following: compute the travel duration (basically a numeric value) to a set of points evenly distributed on a grid around the given position (e.g. 0.5km east, 0.5 km east-0.5km north, 0.5 km east-1 km north etc.). This points would represent the centers of square-shaped areas and I will consider the travel duration to the center as the travel duration to anywhere in the area. Display these areas as colored squares on a Google Maps in a heatmap style.
A good example of something that looks alike is this: http://project.wnyc.org/transit-time/#40.72280,-73.95464,12,709 .
So, my questions are:
Does it seem like a good strategy?
Is there a better visualisation strategy for something like this?
How can I create those square-shaped colored areas on Google Maps?
Thanks!
Calculating duration would surely involve traffic flow rather than simply distance. If your calculations are purely on distance you could use the Google Maps direction requests to calculate the distance to each point.
I'm not sure a heat map is the way forward for this scenario.
There a number of way you could achieve this. Here's a few:
a. Use a custom overlay
(https://developers.google.com/maps/documentation/javascript/examples/overlay-simple)
b. Draw polygons on the map and give them different colours based on
the journey duration. This would involve taking the area in question and slicing it up in to polygons however you need to. These polygons could take the same shape as your example. You would need to be rather precise with your latlng. SQL's spacial querys would help you here depending on the tech your using. (https://developers.google.com/maps/documentation/javascript/examples/polygon-arrays)
c. Depending on how specific you wanted to be you could draw circles with different radius value and different colours.
d. You could make custom markers in the shapes you require and add them to the map in the correct latlng in order to fill an area. You could have different markers for different duration and add them accordingly.
I'm sure there are other options as well.

How to simplify (reduce number of points) in KML?

I have a similar problem to this post. I need to display up to 1000 polygons on an embedded Google map. The polygons are in a SQL database, and I can render each one as a single KML file on the fly using a custom HttpHandler (in ASP.NET), like this http://alpha.foresttransparency.org/concession.1.kml .
Even on my (very fast) development machine, it takes a while to load up even a couple dozen shapes. So two questions, really:
What would be a good strategy for rendering these as markers instead of overlays once I'm beyond a certain zoom level?
Is there a publicly available algorithm for simplifying a polygon (reducing the number of points) so that I'm not showing more points than make sense at a certain zoom level?
For your second question: you need the Douglas-Peucker Generalization Algorithm
For your first question, could you calculate the area of a particular polygon, and relate each zoom level to a particular minimum area, so as you zoom in or out polygon's disappear and markers appear depending on the zoom level.
For the second question, I'd use Mark Bessey's suggestion.
I don't know much aobut KML, but I think the usual solution to question #2 involves iterating over the points, and deleting any line segments under a certain size. This will cause some "unfortunate" effects in some cases, but it's relatively fast and easy to do.
I would recommend 2 things:
- Calculate and combine polygons that are touching. This involves a LOT of processing and hard math, but I've done it so I know it's possible.
- Create your own overlay instead of using KML in PNG format, while you combine them in the previous suggestion. You'll have to create a LOT of PNGs but it is blazing fast on the client.
Good luck :)
I needed a solution to your #2 question a little bit ago and after looking at a few of the available line-simplification algorithms, I created my own.
The process is simple and it seems to work well, though it can be a bit slow if you don't implement it correctly:
P[0..n] is your array of points
Let T[n] be defined as the triangle formed by points P[n-1], P[n], P[n+1]
Max is the number of points you are trying to reduce this line to.
Calculate the area of every possible triangle T[1..n-1] in the set.
Choose the triangle T[i] with the smallest area
Remove the point P[i] to essentially flatten the triangle
Recalculate the area of the affected triangles T[n-1], T[n+1]
Go To Step #2 if the number of points > Max