polygon

sp::over() for point in polygon analysis

有些话、适合烂在心里 提交于 2019-11-27 00:54:34
问题 I have a shapefile named "ind_adm" and a SpatialPointsDataFrame called "pnts". The "pnts" contains points generated at random, and some of the points overlap with the polygon. See picture below. Now, I want do do a point in polygon analysis, i.e. I want to find out which points lie inside the gray polygon representing the boundary of India. For this I am using the over() function in the sp library. pt.in.poly <- sp::over(ind_adm, pnts, fn = mean) #do the join However, the output I am getting

polygon union without holes

北城余情 提交于 2019-11-27 00:37:58
问题 Im looking for some fairly easy (I know polygon union is NOT an easy operation but maybe someone could point me in the right direction with a relativly easy one) algorithm on merging two intersecting polygons. Polygons could be concave without holes and also output polygon should not have holes in it. Polygons are represented in counter-clockwise manner. What I mean is presented on a picture. As you can see even if there is a hole in union of polygons I dont need it in the output. Input

How to determine if a point is inside a 2D convex polygon?

故事扮演 提交于 2019-11-27 00:31:47
I have a convex polygon (typically just a rotated square), and I know all of 4 points. How do I determine if a given point (yellow/green) is inside the polygon? EDIT: For this particular project, I don't have access to all of the libraries of the JDK, such as AWT. Dean Povey This page: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html shows how to do this for any polygon. I have a Java implementation of this, but it is too big to post here in its entirety. However, you should be able to work it out: class Boundary { private final Point[] points; // Points making up the

How to attach a simple data.frame to a SpatialPolygonDataFrame in R?

℡╲_俬逩灬. 提交于 2019-11-27 00:15:03
问题 I have (again) a problem with combining data frames in R. But this time, one is a SpatialPolygonDataFrame ( SPDF ) and the other one is usual data.frame ( DF ). The SPDF has around 1000 rows the DF only 400. Both have a common column, QDGC Now, I tried oo <- merge(SPDF,DF, by="QDGC", all=T) but this only results in a normal data.frame, not a spatial polygon data frame any more. I read somewhere else, that this does not work, but I did not understand what to do in such a case (has to do

Algorithm to generate random 2D polygon

风流意气都作罢 提交于 2019-11-27 00:14:18
问题 I'm not sure how to approach this problem. I'm not sure how complex a task it is. My aim is to have an algorithm that generates any polygon. My only requirement is that the polygon is not complex (i.e. sides do not intersect). I'm using Matlab for doing the maths but anything abstract is welcome. Any aid/direction? EDIT: I was thinking more of code that could generate any polygon even things like this: 回答1: There's a neat way to do what you want by taking advantage of the MATLAB classes

Finder what point is to the left of a line/point after spinning it

坚强是说给别人听的谎言 提交于 2019-11-26 22:11:14
问题 I am currently trying to write a shader in unity that draws a triangular pattern around countries in a risk-styled game if both countries are not owned by the same player (visual aid to see your borders). Right now, I'm having an issue with making the shader set the countries properly. It always sets country 0 to the left, and country 1 to the right - country 0 and 1 are set programically. The line, a border, can be between 0 and 359 degrees. How I find the countries 0 and 1 is I draw 3

Mathplotlib draw triangle with gradient fill

↘锁芯ラ 提交于 2019-11-26 22:10:47
问题 I have to draw a triangle in Python using mathplotlib. This is how it should eventually look like: My objective is, once drawn the triangle, to plot some points on it. At the moment I can draw the triangle just fine: import matplotlib.pyplot as plt from matplotlib.patches import Polygon fig = plt.figure() ax = fig.add_subplot(111, aspect='equal') ax.add_patch(Polygon([[0,0],[0,1],[1,0]], closed=True,fill=True)) ax.set_xlim((0,1)) ax.set_ylim((0,1)) plt.show() But I can only fill it with a

Google Maps Polygons self intersecting detection

坚强是说给别人听的谎言 提交于 2019-11-26 21:29:14
问题 I'm trying to implement a polygon self intersection algorithm from Google Maps API V3 polygons. The goal is just to detect if yes or no, a simple polygon drawn by the user is self crossing. I have found this very interesting link, but it assumes that coordinates of the polygon's vertices are given on geoJSON format. However, this isn't my case ; I'm only able to retrieve polygons coordinates using polygon.getPath() into a polygoncomplete event. This is how i retrieve the coordinates : google

How to fill geom_polygon with different colors above and below y = 0?

对着背影说爱祢 提交于 2019-11-26 20:56:11
Considering the following polygon plot: ggplot(df, aes(x=year,y=afw)) + geom_polygon() + scale_x_continuous("", expand=c(0,0), breaks=seq(1910,2010,10)) + theme_bw() However, i want to fill this with two different colors. For example red for the black areas above 0 and blue for the black areas below 0 . Unfortunately, using fill=col doesn't fill the correct areas. I tried the following code (I added the geom_line in order to illustrate where the border of the fill should be): ggplot(df, aes(x=year,y=afw)) + geom_line() + geom_polygon(aes(fill=col), alpha=0.5) + scale_x_continuous("", expand=c

How to create thiessen polygons from points using R packages?

十年热恋 提交于 2019-11-26 20:28:54
问题 I have multiple sets of points (for different years ~20) I want to generate thiessen polygons for each set of points using r spatial packages. I know this can be done using GIS but as i want a batch process something in R would be helpful. 回答1: You haven't given us access to your data, but here's an example for points representing cities of the world, using an approach described by Carson Farmer on his blog. Hopefully it'll get you started... # Carson's Voronoi polygons function