Skip to content

Maptools, polylines to polygon and the .dwg format

2 messages · FloydGlz, Nikhil Kaza

#
Let's see if i can explain myself properly...

Im doing some work on categorizing diseases per area, so i have a map (a
.dwg file) that has all the states and municipalities, and my end work has
to be the same map but with different colors depending on the number of
cases for each disease.

Now, for example, in this page, http://www.gadm.org/country, you can
download a map (i use Mexico for the example, and i download it as a shape
file), then, i load it to R with maptools and the readShapePoly function;
using this i can subset specific regions and colour it according to my
needs, pretty easy and useful. Another great thing, is that in the .dbf file
(im not 100% is that file but im guessing it is) contains all the ID's,
which i can access with the names() function of R, and i can search for a
specific name or state, BECAUSE IT EXISTS SUCH ID.

Now my problem is that i dont know how to manipulate this ID's, because in
the example they are already there, but with the data i have (the .dwg
file), is pretty much inexistent, how do i create/edit an attribute, so i
can add it to the .shp/.dbf file? if i want to create a category named
Municipalities, so each polygon (region of the map) has a unique name, how
do i do that?

For example, in the shp file of mexico listed in the example, one can create
a map with the following code

library(maptools)
mexmap <- readShapePoly("MEX_adm2.shp")
names(mexmap)
df <- which(mexmap[[5]] == "Distrito Federal")
plot(mexmap[df,])
library(gplots)
showpanel <- function(col){image(z=matrix(1:100, ncol=1), col=col, xaxt="n",
yaxt="n")}
showpanel(colorpanel(6,low="skyblue",high="darkblue")) #so i can see the
colors
colore <- colorpanel(6,low="skyblue",high="darkblue")
colore <- rep(colore,length.out=16)
plot(mexmap[df,],col=colore)

In the end is easier because i have the names i want, and i can manipulate
the regions needed. I want to do the same with my file.

I appreciate any suggestions, thank very much for your time.

------------------------------------
Melvin Jesus Noe Gonzalez
Undergraduate Genomics Student 
UNAM MEX
mnoe at lcg.unam.mx
#
I am not sure I understand. I havent worked with Dwg in a long time,  
but my sense is they are just geometric boundary files. There is no  
`data' attached to them.

Two options.
1. convert dwg to shapefile and do a spatial join. IF the dwg file is  
points, this what you should do.
2. if the dwg files are essentially boundaries of polygons in the  
shapefile, create a new table with ID of the polygon and count of  
diseases and then do a join with merge.



Nikhil Kaza
Asst. Professor,
City and Regional Planning
University of North Carolina

nikhil.list at gmail.com
On Jul 5, 2010, at 5:41 PM, FloydGlz wrote: