Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Assign points to polygon shapefile

    Dear Statalist users:
    Is there a way to assign points from one file to locations within polygons in Stata? Let's say I have coordinates for several monuments in a file and that I also have a shapefile with boundaries for several countries. Can I use stata to create a dataset that says in which country each of the monuments is located?
    Thanks!
    Maria Ana Vitorino

  • #2
    Maria Ana,

    If the coordinates in the monument file are latitudes and longitudes (which they usually are), then you probably don't need to refer to the shape file to figure out what countries they are in. For example, you could use the geocode3 program (available from SSC) to get the address corresponding to the latitude and longitude:

    Code:
    ssc install geocode3
    gen coord=string(lat)+","+string(lon)
    geocode3, coord(coord)
    gen country=word(r_addr,-1)
    list lat lon country
    Regards,
    Joe

    Comment


    • #3
      Thanks Joe, but actually the regions I have in the shapefile are not countries but rather specific user-defined shapes. Do you know if there is a way of solving my problem without having to use some software like QGIS?
      Thanks!
      Maria Ana

      Comment


      • #4
        See gpsmap

        Comment


        • #5
          Thanks. I couldn't find gpsmap online but I've contacted the author of the program hoping that he can provide me with it. If there is another alternative that is available please let me know.

          Comment


          • #6
            The algorithm used in spmap to determine if a point is inside a polygon is actually quite straight forward and you might be able to implement it yourself. Follow the link that Sergiy provided and look at the PowerPoint presentation starting at around Slide 35. Basically, you just count the number of points in a particular polygon that have the same latitude and a higher (or lower) longitude as the point in question. If the number is even, it is outside; if it is odd, it is inside.

            Comment


            • #7
              Dear Joe,
              Thanks for the insight. I looked at the spmap syntax but was unable to figure out which part (algorithm) you are referring to. If you could point that out it would be great.
              Thanks!

              Comment


              • #8
                Maria-Ana,

                Sorry, I meant to refer to gpsmap, the algorithm of which is described in the PowerPoint presentation Sergiy referred to. I was going to give you some suggested code for implementing the algorithm, but it turned out to be more complicated than I thought. I will get back to you if I come up with something.

                Regards,
                Joe

                Comment

                Working...
                X