[Qgis-user] shp (produced with QGIS) into R: missing first field?

Marco Hugentobler marco.hugentobler at karto.baug.ethz.ch
Thu Nov 20 06:01:17 PST 2008


Hi Agustin

The field "id" is a unique identifier for qgis, but not an attribute in the dbf 
table.

Regards,
Marco

On Thursday 20 November 2008 14:48:16 Agustin Lobo wrote:
> When I inspect the table of a shp in QGIS I can see a field
> "id" with unique values for each row (polygon), but
>
> once I import it into R, that first field is not there:
>  > metrop1spdf <- readOGR("/media/IOMEGA
>
> HDD/Mario/BCNmetrop/GEODATA_BCN/Shape_final2c", layer="SHAPE_FINAL2C")
> OGR data source with driver: ESRI Shapefile
> Source: "/media/IOMEGA HDD/Mario/BCNmetrop/GEODATA_BCN/Shape_final2c",
> layer: "SHAPE_FINAL2C"
> with  3272  rows and  49  columns
>
>  > save.image()
>  > str(metrop1spdf,2)
>
> Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
>    ..@ data       :'data.frame':	3272 obs. of  49 variables:
>    ..@ polygons   :List of 3272
>    ..@ plotOrder  : int [1:3272] 703 1501 140 1467 1416 1336 82 2127
> 2796 1387 ...
>    ..@ bbox       : num [1:2, 1:2] 421333 4576848 438994 4593850
>    .. ..- attr(*, "dimnames")=List of 2
>    ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
>
>  > str(metrop1spdf at data)
>
> 'data.frame':	3272 obs. of  49 variables:
>   $ FID_inters: int  0 0 1 1 2 3 4 5 6 7 ...
>   $ FID_UC    : int  0 0 0 0 0 0 0 0 0 0 ...
>   $ ID_GRAFIC : int  1 1 1 1 1 1 1 1 1 1 ...
>   $ N_VERTEXS : int  5770 5770 5770 5770 5770 5770 5770 5770 5770 5770 ...
>   $ PERIMETRE : num  191741 191741 191741 191741 191741 ...
>   $ PERIMETREE: num  191807 191807 191807 191807 191807 ...
>   $ AREA      : num  4444 276 5364 790 3935 ...
> etc
>
> As I want to operate with that table in R (which implies merging with
> other DF) and produce
> a new SPDF and export to shp, I worry for not having that field.
> Or is it somehow implied in R? I'm surprised by the fact
> that the first value in the id field in QGIS is 0 and not 1. I
> think that such an id in R would start by 1, am I wrong?
>
> Agus

-- 
Dr. Marco Hugentobler
Institute of Cartography
ETH Zurich
Technical Advisor QGIS Project Steering Committee



More information about the Qgis-user mailing list