jitter within polygon

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

jitter within polygon

Paul Lantos
I am trying to figure out how to randomly jitter points within an overlying polygon structure.

I can easily jitter the points themselves, but I would like this to be constrained by the boundaries of polygons containing the points.

This isn't for visualization - I can do that easily enough in GIS. I actually need to generate coordinates.

Thanks,
Paul

Paul M. Lantos, MD, MS GIS, FIDSA, FAAP, FACP                       Contact
Departments of Internal Medicine and Pediatrics                           919-684-6355 (Pediatric Infectious Diseases)
    Pediatric Infectious Diseases                                                                919-681-8263 (Hospital Medicine)
    General Internal Medicine                                                                    [hidden email]
Duke University School of Medicine                                                     @PaulLantos
Duke Global Health Institute


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: jitter within polygon

Baldwin, Jim -FS
Sounds like you need a "point-in-polygon" routine to determine if the jittered point is still within the polygon.

R has several such routines.  Here are two:

  pnt.in.poly in the SDMTools package
  point.in.polygon in the sp package

Mathematica has several options, too.

Jim



-----Original Message-----
From: R-sig-Geo [mailto:[hidden email]] On Behalf Of Paul Lantos
Sent: Friday, January 27, 2017 9:30 PM
To: [hidden email]
Subject: [R-sig-Geo] jitter within polygon

I am trying to figure out how to randomly jitter points within an overlying polygon structure.

I can easily jitter the points themselves, but I would like this to be constrained by the boundaries of polygons containing the points.

This isn't for visualization - I can do that easily enough in GIS. I actually need to generate coordinates.

Thanks,
Paul

Paul M. Lantos, MD, MS GIS, FIDSA, FAAP, FACP                       Contact
Departments of Internal Medicine and Pediatrics                           919-684-6355 (Pediatric Infectious Diseases)
    Pediatric Infectious Diseases                                                                919-681-8263 (Hospital Medicine)
    General Internal Medicine                                                                    [hidden email]
Duke University School of Medicine                                                     @PaulLantos
Duke Global Health Institute


[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo




This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: jitter within polygon

Paul Lantos
Thanks, Jim. There isn't a way to specify the polygons a priori in order to constrain the jittering?

Paul

-----Original Message-----
From: Baldwin, Jim -FS [mailto:[hidden email]]
Sent: Saturday, January 28, 2017 12:47 AM
To: Paul Lantos <[hidden email]>; [hidden email]
Subject: RE: jitter within polygon

Sounds like you need a "point-in-polygon" routine to determine if the jittered point is still within the polygon.

R has several such routines.  Here are two:

  pnt.in.poly in the SDMTools package
  point.in.polygon in the sp package

Mathematica has several options, too.

Jim



-----Original Message-----
From: R-sig-Geo [mailto:[hidden email]] On Behalf Of Paul Lantos
Sent: Friday, January 27, 2017 9:30 PM
To: [hidden email]
Subject: [R-sig-Geo] jitter within polygon

I am trying to figure out how to randomly jitter points within an overlying polygon structure.

I can easily jitter the points themselves, but I would like this to be constrained by the boundaries of polygons containing the points.

This isn't for visualization - I can do that easily enough in GIS. I actually need to generate coordinates.

Thanks,
Paul

Paul M. Lantos, MD, MS GIS, FIDSA, FAAP, FACP                       Contact
Departments of Internal Medicine and Pediatrics                           919-684-6355 (Pediatric Infectious Diseases)
    Pediatric Infectious Diseases                                                                919-681-8263 (Hospital Medicine)
    General Internal Medicine                                                                    [hidden email]
Duke University School of Medicine                                                     @PaulLantos
Duke Global Health Institute


[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dsig-2Dgeo&d=CwIFAg&c=imBPVzF25OnBgGmVOlcsiEgHoG1i6YHLR0Sj_gZ4adc&r=pCiIbVPBNWU0azo0D48ChUH_fawb-FalNVOf1sUn1r4&m=i4hWU9_Gy7AChLfLUddISsWbzbyNPkZ_ooonniSZoIY&s=ner0DbrTVNhQ2EgrDupUQkMsjZKVTOJHFF9CSyjUypU&e= 




This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: jitter within polygon

obrl soil
In reply to this post by Paul Lantos
Maybe try this sampler - https://gist.github.com/obrl-soil/839b192da46978351733483421db22f8 

You’d want to run it multiple times and cycle through the outputs, if I’m interpreting your request correctly.

Cheers
@obrl_soil

From: Paul Lantos
Sent: Saturday, 28 January 2017 3:30 PM
To: [hidden email]
Subject: [R-sig-Geo] jitter within polygon

I am trying to figure out how to randomly jitter points within an overlying polygon structure.

I can easily jitter the points themselves, but I would like this to be constrained by the boundaries of polygons containing the points.

This isn't for visualization - I can do that easily enough in GIS. I actually need to generate coordinates.

Thanks,
Paul

Paul M. Lantos, MD, MS GIS, FIDSA, FAAP, FACP                       Contact
Departments of Internal Medicine and Pediatrics                           919-684-6355 (Pediatric Infectious Diseases)
    Pediatric Infectious Diseases                                                                919-681-8263 (Hospital Medicine)
    General Internal Medicine                                                                    [hidden email]
Duke University School of Medicine                                                     @PaulLantos
Duke Global Health Institute


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: jitter within polygon

Baldwin, Jim -FS
In reply to this post by Paul Lantos
Point-in-polygon routines are pretty fast and straightforward to use.  If it's about reducing computing time, then maybe for "irregular" polygons it would be easier to stratify the points into two groups:  those points whose jittering would not go outside the polygon and those that might and only use point-in-polygon on the potentially outside points.  However, I'd try the point-in-polygon route first and see if it is fast enough first.


Jim


-----Original Message-----
From: Paul Lantos [mailto:[hidden email]]
Sent: Friday, January 27, 2017 9:49 PM
To: Baldwin, Jim -FS <[hidden email]>; [hidden email]
Subject: RE: jitter within polygon

Thanks, Jim. There isn't a way to specify the polygons a priori in order to constrain the jittering?

Paul

-----Original Message-----
From: Baldwin, Jim -FS [mailto:[hidden email]]
Sent: Saturday, January 28, 2017 12:47 AM
To: Paul Lantos <[hidden email]>; [hidden email]
Subject: RE: jitter within polygon

Sounds like you need a "point-in-polygon" routine to determine if the jittered point is still within the polygon.

R has several such routines.  Here are two:

  pnt.in.poly in the SDMTools package
  point.in.polygon in the sp package

Mathematica has several options, too.

Jim



-----Original Message-----
From: R-sig-Geo [mailto:[hidden email]] On Behalf Of Paul Lantos
Sent: Friday, January 27, 2017 9:30 PM
To: [hidden email]
Subject: [R-sig-Geo] jitter within polygon

I am trying to figure out how to randomly jitter points within an overlying polygon structure.

I can easily jitter the points themselves, but I would like this to be constrained by the boundaries of polygons containing the points.

This isn't for visualization - I can do that easily enough in GIS. I actually need to generate coordinates.

Thanks,
Paul

Paul M. Lantos, MD, MS GIS, FIDSA, FAAP, FACP                       Contact
Departments of Internal Medicine and Pediatrics                           919-684-6355 (Pediatric Infectious Diseases)
    Pediatric Infectious Diseases                                                                919-681-8263 (Hospital Medicine)
    General Internal Medicine                                                                    [hidden email]
Duke University School of Medicine                                                     @PaulLantos
Duke Global Health Institute


[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dsig-2Dgeo&d=CwIFAg&c=imBPVzF25OnBgGmVOlcsiEgHoG1i6YHLR0Sj_gZ4adc&r=pCiIbVPBNWU0azo0D48ChUH_fawb-FalNVOf1sUn1r4&m=i4hWU9_Gy7AChLfLUddISsWbzbyNPkZ_ooonniSZoIY&s=ner0DbrTVNhQ2EgrDupUQkMsjZKVTOJHFF9CSyjUypU&e= 




This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: jitter within polygon

Paul Lantos
Ok, thanks. It's for about 100,000 points within thousands of polygons, and they need to 1) remain within a polygon and 2) retain original attribute data. Could be a challenging workflow...
Paul

-----Original Message-----
From: Baldwin, Jim -FS [mailto:[hidden email]]
Sent: Saturday, January 28, 2017 1:22 AM
To: Paul Lantos <[hidden email]>; [hidden email]
Subject: RE: jitter within polygon

Point-in-polygon routines are pretty fast and straightforward to use.  If it's about reducing computing time, then maybe for "irregular" polygons it would be easier to stratify the points into two groups:  those points whose jittering would not go outside the polygon and those that might and only use point-in-polygon on the potentially outside points.  However, I'd try the point-in-polygon route first and see if it is fast enough first.


Jim


-----Original Message-----
From: Paul Lantos [mailto:[hidden email]]
Sent: Friday, January 27, 2017 9:49 PM
To: Baldwin, Jim -FS <[hidden email]>; [hidden email]
Subject: RE: jitter within polygon

Thanks, Jim. There isn't a way to specify the polygons a priori in order to constrain the jittering?

Paul

-----Original Message-----
From: Baldwin, Jim -FS [mailto:[hidden email]]
Sent: Saturday, January 28, 2017 12:47 AM
To: Paul Lantos <[hidden email]>; [hidden email]
Subject: RE: jitter within polygon

Sounds like you need a "point-in-polygon" routine to determine if the jittered point is still within the polygon.

R has several such routines.  Here are two:

  pnt.in.poly in the SDMTools package
  point.in.polygon in the sp package

Mathematica has several options, too.

Jim



-----Original Message-----
From: R-sig-Geo [mailto:[hidden email]] On Behalf Of Paul Lantos
Sent: Friday, January 27, 2017 9:30 PM
To: [hidden email]
Subject: [R-sig-Geo] jitter within polygon

I am trying to figure out how to randomly jitter points within an overlying polygon structure.

I can easily jitter the points themselves, but I would like this to be constrained by the boundaries of polygons containing the points.

This isn't for visualization - I can do that easily enough in GIS. I actually need to generate coordinates.

Thanks,
Paul

Paul M. Lantos, MD, MS GIS, FIDSA, FAAP, FACP                       Contact
Departments of Internal Medicine and Pediatrics                           919-684-6355 (Pediatric Infectious Diseases)
    Pediatric Infectious Diseases                                                                919-681-8263 (Hospital Medicine)
    General Internal Medicine                                                                    [hidden email]
Duke University School of Medicine                                                     @PaulLantos
Duke Global Health Institute


[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dsig-2Dgeo&d=CwIFAg&c=imBPVzF25OnBgGmVOlcsiEgHoG1i6YHLR0Sj_gZ4adc&r=pCiIbVPBNWU0azo0D48ChUH_fawb-FalNVOf1sUn1r4&m=i4hWU9_Gy7AChLfLUddISsWbzbyNPkZ_ooonniSZoIY&s=ner0DbrTVNhQ2EgrDupUQkMsjZKVTOJHFF9CSyjUypU&e= 




This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: jitter within polygon

Paul Lantos
In reply to this post by obrl soil
Thanks, will take a look!

Paul

From: [hidden email] [mailto:[hidden email]]
Sent: Saturday, January 28, 2017 1:03 AM
To: Paul Lantos <[hidden email]>; [hidden email]; obrl_soil <[hidden email]>
Subject: RE: [R-sig-Geo] jitter within polygon

Maybe try this sampler - https://gist.github.com/obrl-soil/839b192da46978351733483421db22f8<https://urldefense.proofpoint.com/v2/url?u=https-3A__gist.github.com_obrl-2Dsoil_839b192da46978351733483421db22f8&d=CwMGaQ&c=imBPVzF25OnBgGmVOlcsiEgHoG1i6YHLR0Sj_gZ4adc&r=pCiIbVPBNWU0azo0D48ChUH_fawb-FalNVOf1sUn1r4&m=JsxKvUqShLm0BOKkwOldeOLeDanBw61LAAhZ6snUYW4&s=7U1IpidxWg5KFM1OLw0uCC1KWrtiHLMn9m0W6UfKPtQ&e=>

You’d want to run it multiple times and cycle through the outputs, if I’m interpreting your request correctly.

Cheers
@obrl_soil<mailto:[hidden email]>

From: Paul Lantos<mailto:[hidden email]>
Sent: Saturday, 28 January 2017 3:30 PM
To: [hidden email]<mailto:[hidden email]>
Subject: [R-sig-Geo] jitter within polygon

I am trying to figure out how to randomly jitter points within an overlying polygon structure.

I can easily jitter the points themselves, but I would like this to be constrained by the boundaries of polygons containing the points.

This isn't for visualization - I can do that easily enough in GIS. I actually need to generate coordinates.

Thanks,
Paul

Paul M. Lantos, MD, MS GIS, FIDSA, FAAP, FACP                       Contact
Departments of Internal Medicine and Pediatrics                           919-684-6355 (Pediatric Infectious Diseases)
    Pediatric Infectious Diseases                                                                919-681-8263 (Hospital Medicine)
    General Internal Medicine                                                                    [hidden email]<mailto:[hidden email]>
Duke University School of Medicine                                                     @PaulLantos
Duke Global Health Institute


           [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]<mailto:[hidden email]>
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: jitter within polygon

Rolf Turner
In reply to this post by Paul Lantos

On 28/01/17 18:29, Paul Lantos wrote:

> I am trying to figure out how to randomly jitter points within an
> overlying polygon structure.
>
> I can easily jitter the points themselves, but I would like this to
> be constrained by the boundaries of polygons containing the points.
>
> This isn't for visualization - I can do that easily enough in GIS. I
> actually need to generate coordinates.

You can do this easily in spatstat by making each polygon into an object
of class "owin" (see e.g. the "shapefiles" vignette) and then using the
function rjitter() (with retry=TRUE).

Note that if you have a collection of polygons some of which are close
to being contiguous, it is possible (or at least conceivable) for a
jittered point to "jump" to a location inside a different polygon.
Hence if you were to represent your collection of polygons as a single
(disconnected) "owin" object you would run the risk of incurring this
"jumping" phenomenon.  Hence it would be safer to bundle your collection
of polygons into a list, and apply rjitter() to each list entry (using
lapply()).

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo