[R] how to import map data (maptools?) from a html set of 'coords'

Henrique Dallazuanna wwwhsd at gmail.com
Wed Mar 3 21:00:47 CET 2010


You can try this also:

plot(m <- matrix(v, ncol = 2, byrow = TRUE))
polygon(m)

On Wed, Mar 3, 2010 at 4:49 PM, sylvain willart
<sylvain.willart at gmail.com> wrote:
> SOLVED,
>
> example from the "Nord-Pas-de-Calais" region:
>
> ############################################
> v <- c(237,55,236,58,229,57,214,57,203,55,197,54,187,48,179,46,179,35,180,31,184,26,197,23,201,24,202,31,207,34,213,31,216,37,219,41,228,46,234,47,237,55)
>
> seqx <- seq(1,length(v),by=2)
> seqy <- seq(2,length(v),by=2)
>
> vx <- c()
> for (j in seqx) {
> vx <- c(vx,v[j])
>      }
> vy <- c()
> for (j in seqy) {
> vy <- c(vy,v[j])
>      }
> plot(vx,-vy)
> polygon(vx,-vy,border="red")
> ############################################
>
> thanks for your tips,
>
> Sylvain
> Now, I just have to read it using maptools...
>
> 2010/3/3 sylvain willart <sylvain.willart at gmail.com>:
>> Hi
>> thanks for your reply,
>> I'll try to better explain my request...
>> the data do not come from a file with a specific extension, this is
>> just some lines I copied pasted from a source html file
>>
>> The web page is:
>> http://www.insee.fr/fr/ppp/bases-de-donnees/donnees-detaillees/duicq/accueil.asp
>> it displays an (interactive) map of France with all the regions
>>
>> to access the source: edit/source , or Ctrl+U in a web browser
>>
>> By the middle of the html source file, there is an html object called
>> map (<map> ... </map>) with a set of coordinates representing the
>> polygons of each region,
>>
>> These coordinates are just location of points: x1,y1,x2,y2,x3,y3...
>> that draw polygons. They are not proper longitude or latitude and
>> their "origine" is just the corner of the image the html file
>> generates...
>>
>> I am aware those are not "real" geographic data (That's why I didn't
>> post my question to sig-geo, it looks more like a problem of
>> graphics), but these are the coordinates one need to "draw" a map (and
>> eventually import it to a more specific package like spatstat)
>>
>> So, what I would like to do is: using those coordinates to draw such a
>> map, and eventually use that map for distance or area calculus (which
>> do not need to be extremely precise...)
>>
>> sylvain
>>
>>
>> 2010/3/3 Michael Denslow <michael.denslow at gmail.com>:
>>> Hi Sylvian,
>>>
>>>
>>> On Tue, Mar 2, 2010 at 1:15 PM, sylvain willart
>>> <sylvain.willart at gmail.com> wrote:
>>>> Dear R users,
>>>>
>>>> I would like to draw map and import it in maptools/spatstat packages.
>>>>
>>>> The 'raw data' I have come from a web page (<map>...</map>) and are
>>>> basically a list of coordinates of a polygon.
>>>>
>>>> I would like to know how to import them in R; I checked the maptools
>>>> packages, but all the examples use existing .dbf files.
>>>>
>>>> I just have a (serie of) text file(s) looking like this:
>>>>
>>>> For example, for the French Region Burgundy:
>>>>
>>>> <area  href="region.asp?reg=26" shape="poly" title="Bourgogne" alt="Bourgogne"
>>>> coords="208,121,211,115,221,113,224,115,225,120,229,122,232,128,251,125,255,
>>>> 130,256,136,266,138,268,148,267,154,263,160,267,168,267,180,262,
>>>> 175,256,178,254,184,248,184,243,187,237,187,232,185,234,181,227,
>>>> 171,216,171,212,166,211,155,208,149,208,135,211,132,213,125,208,
>>>> 121">
>>>
>>> It is not clear (to me) from your example what kind of file this is.
>>> Maybe XML, it does not look like GML. readOGR() in the rgdal package
>>> may be a better route to explore, but you need to determine what file
>>> structure is first.
>>>
>>>> any idea welcome,
>>>>
>>>> sylvain
>>>>
>>>> (If anayone is interested with that type of data, they're available at
>>>> the INSEE website
>>>
>>> I can not easily find an example on this site. Perhaps you could
>>> provide a direct link to the file. Lastly, I suspect that the
>>> r-sig-geo mailing list would get you some better answers.
>>>
>>> Michael
>>>
>>> --
>>> Michael Denslow
>>>
>>> I.W. Carpenter Jr. Herbarium [BOON]
>>> Department of Biology
>>> Appalachian State University
>>> Boone, North Carolina U.S.A.
>>> -- AND --
>>> Communications Manager
>>> Southeast Regional Network of Expertise and Collections
>>> sernec.org
>>>
>>> 36.214177, -81.681480 +/- 3103 meters
>>>
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list