Open fahad-mirza opened 1 year ago
I think you can use layertype symbol
to create buffers. Here's an example. First load some data:
local url http://fmwww.bc.edu/repec/bocode/i/
local url shp/it/
geoframe create regions `url'Italy-RegionsData.dta, id(id) coord(xcoord ycoord) ///
shpfile(`url'Italy-RegionsCoordinates.dta)
geoframe create capitals `url'Italy-Capitals.dta, coord(xcoord ycoord)
No I use symbol
to draw a buffer with radius 100'000 km around Rome:
geoplot (area regions) ///
(symbol capitals if city=="Roma", size(100000) color(Green%50))
Use symboli
to create buffers around arbitrary coordinates. The following command would create the same graph above, as these are the coordinates of Rome.
geoplot (area regions) ///
(symboli 4644022.5 788894.1, size(100000) color(Green%50))
For the second question, geoframe spjoin
may be useful. However you would first have to create a frame that contains the coordinates of the buffer. I'll try to come up with an example.
In principle, here is how this could be done:
// get data
local url http://fmwww.bc.edu/repec/bocode/i/
local url shp/it/
geoframe create regions `url'Italy-RegionsData.dta, id(id) coord(xcoord ycoord) ///
shpfile(`url'Italy-RegionsCoordinates.dta)
geoframe create capitals `url'Italy-Capitals.dta, coord(xcoord ycoord)
// create buffer
geoplot (symbol capitals if city=="Roma", size(100000)), ///
nodraw frame(buffer)
geoframe create, id(LAYER) coordinates(X Y)
// spatial join
frame change capitals
geoframe spjoin buffer NearRome, noset
replace NearRome = 0 if NearRome>=.
// final graph
geoplot (area regions) (symbol capitals if city=="Roma", size(100000)) ///
(point capitals NearRome, discrete label(1 = "Nope" 2 = "Yes, near Rome" ))
However, two remarks:
geoframe spjoin
will return error due to an issue in Stata related to Mata views and frames; I added a workaround, but did not yet upload the new version to github; it may take a moment, because there are other things I want to take care of firstgeoplot
to generate the buffer is odd; I put it on the list to add command geoframe buffer
to generate buffers; possible an idea could also be to add a buffer()
option to layertype point
which will create the buffer and do the spatial join on the flyThis is great! Thank you for doing this and looking forward to this update in geoplot!
Will this also be possible if we were to create a buffer around a line or polygon? For example lakes and roads?
Hm, yes, I guess. Not sure though what it would mean in case of a polygon, just add a margin of fixed width around the polygon? This may be a bit tricky, one would have to determine the outer bound of the margin in case of nonconvex shapes or if a buffer is to be constructed around multiple polygons. Or add a convex hull with some padding?
In the newest update there is now a command called geoframe symbol
that can be used to generate symbol shapes directly, without taking the detour through geoplot, nodraw
. Example:
// get data
local url http://fmwww.bc.edu/repec/bocode/i/
geoframe create regions `url'Italy-RegionsData.dta, id(id) coord(xcoord ycoord) ///
shpfile(Italy-RegionsCoordinates.dta)
geoframe create capitals `url'Italy-Capitals.dta, coord(xcoord ycoord)
// create buffer
geoframe symbol Rome_buffer if city=="Roma", size(100000)
// spatial join
geoframe spjoin Rome_buffer NearRome, noset
replace NearRome = NearRome<.
// final graph
geoplot (area regions) (area Rome_buffer) ///
(point capitals i.NearRome, label(0 = "Nope" 1 = "Yes, near Rome" ))
Creating buffers for lines and polygons seems very complicated and I did not yet find any hint on an easy to implement algorithm. So I cannot make any promises.
This is really nice! I am not well versed in gis but maybe these documents might help with finding a n easy solution
https://www.tandfonline.com/doi/pdf/10.1080/10095020.2012.747643
Thanks. Well, easy it doesn't seem... :)
Hi Ben. Thank you so much for doing this and also a big fan of your work. Hope to learn coding from you as well some day.
I just want request if a feature of making Buffers can be included in this awesome package you are developing?
Another followup request to possible consider marking observations that fall within the buffer with a variable as well?
Will be nice to have this feature.