Hi all! I feel like I?m missing something simple. I can access X & Y coordinates like: s <- readShapeLines(elev) head(coordinates(s at lines[[1]]@Lines[[1]])) I can?t seems to find any information on how to access Z and M values. I can easily access those with `shapefiles` package, but it has a limited support for Point Z when writing a shapefile and it is generally not as structured as `maptools`/`sp`. While having Z value as an attribute for an output point is not an issue for me, I do have PolylineZM as an input and I do need an access to both Z & M. Thank you for any suggestions, Mikhail
How do I read/work with PolyLineZM with maptools/sp?
8 messages · Edzer Pebesma, Mikhail Titov, Roger Bivand
On 05/16/2011 08:06 PM, Mikhail Titov wrote:
Hi all! I feel like I?m missing something simple. I can access X & Y coordinates like: s <- readShapeLines(elev) head(coordinates(s at lines[[1]]@Lines[[1]])) I can?t seems to find any information on how to access Z and M values. I can easily access those with `shapefiles` package, but it has a limited support for Point Z when writing a shapefile and it is generally not as structured as `maptools`/`sp`. While having Z value as an attribute for an output point is not an issue for me, I do have PolylineZM as an input and I do need an access to both Z & M.
I would try s$M and s$Z to access M and Z when they are attributes.
Thank you for any suggestions, Mikhail
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster Weseler Stra?e 253, 48151 M?nster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebesma at wwu.de
I would try s$M and s$Z to access M and Z when they are attributes.
But what do I do when they are not? It can work for points, but not a line as I can't have attributes for individual points of a line. I would prefer not to do any extra conversions in GIS before using R. Do I get it right that for now it is better to stick with shapefiles to read PolylineZM? Mikhail
On 05/16/2011 08:22 PM, Mikhail Titov wrote:
I would try s$M and s$Z to access M and Z when they are attributes.
But what do I do when they are not? It can work for points, but not a line as I can't have attributes for individual points of a line. I would prefer not to do any extra conversions in GIS before using R.
as(s, "SpatialPointsDataFrame")
Do I get it right that for now it is better to stick with shapefiles to read PolylineZM? Mikhail
Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster Weseler Stra?e 253, 48151 M?nster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebesma at wwu.de
Edzer: Thank you for your suggestions, but it doesn't help much. It does not recover either Z or M as attributes or anyhow else.
p <- as(s, "SpatialPointsDataFrame") names(p)
[1] "Id" "Lines.NR" "Lines.ID" "Line.NR"
slotNames(p)
[1] "data" "coords.nrs" "coords" "bbox" "proj4string"
head(p at coords)
coords.x1 coords.x2 [1,] 408794.5 4893921 [2,] 409088.3 4893599 [3,] 409165.2 4893484 [4,] 409434.7 4893214 [5,] 409684.9 4893060 [6,] 409742.6 4893060
head(p at data)
Id Lines.NR Lines.ID Line.NR 0 1 1 0 1 0.1 1 1 0 1 0.2 1 1 0 1 0.3 1 1 0 1 0.4 1 1 0 1 0.5 1 1 0 1
p$Z
NULL
p$z
NULL I double checked that I'm working with correct shapefile that has Z values. Mikhail
-----Original Message----- From: Edzer Pebesma [mailto:edzer.pebesma at uni-muenster.de] Sent: Monday, May 16, 2011 1:29 PM To: Mikhail Titov Cc: r-sig-geo at r-project.org Subject: Re: [R-sig-Geo] How do I read/work with PolyLineZM with maptools/sp? On 05/16/2011 08:22 PM, Mikhail Titov wrote:
I would try s$M and s$Z to access M and Z when they are attributes.
But what do I do when they are not? It can work for points, but not a
line as I can't have attributes for individual points of a line. I would prefer not to do any extra conversions in GIS before using R.
as(s, "SpatialPointsDataFrame")
Do I get it right that for now it is better to stick with shapefiles to
read PolylineZM?
Mikhail
-- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster Weseler Stra?e 253, 48151 M?nster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebesma at wwu.de
On Mon, 16 May 2011, Mikhail Titov wrote:
Edzer: Thank you for your suggestions, but it doesn't help much. It does not recover either Z or M as attributes or anyhow else.
The Z is dropped for SpatialPolygons and SpatialLines everywhere. The M is not a standard part of the specification - it isn't obvious what it should be. You'd need to rewrite the C code in shapelib for maptools or rgdal to access these, and create a 4D object. Alternatively, try anything perhaps in Python with OGR to dump 3D points with M as an attribute, and a grouping factor to point to the feature ID in the DBF file. Roger
p <- as(s, "SpatialPointsDataFrame") names(p)
[1] "Id" "Lines.NR" "Lines.ID" "Line.NR"
slotNames(p)
[1] "data" "coords.nrs" "coords" "bbox" "proj4string"
head(p at coords)
coords.x1 coords.x2 [1,] 408794.5 4893921 [2,] 409088.3 4893599 [3,] 409165.2 4893484 [4,] 409434.7 4893214 [5,] 409684.9 4893060 [6,] 409742.6 4893060
head(p at data)
Id Lines.NR Lines.ID Line.NR 0 1 1 0 1 0.1 1 1 0 1 0.2 1 1 0 1 0.3 1 1 0 1 0.4 1 1 0 1 0.5 1 1 0 1
p$Z
NULL
p$z
NULL I double checked that I'm working with correct shapefile that has Z values. Mikhail
-----Original Message----- From: Edzer Pebesma [mailto:edzer.pebesma at uni-muenster.de] Sent: Monday, May 16, 2011 1:29 PM To: Mikhail Titov Cc: r-sig-geo at r-project.org Subject: Re: [R-sig-Geo] How do I read/work with PolyLineZM with maptools/sp? On 05/16/2011 08:22 PM, Mikhail Titov wrote:
I would try s$M and s$Z to access M and Z when they are attributes.
But what do I do when they are not? It can work for points, but not a
line as I can't have attributes for individual points of a line. I would prefer not to do any extra conversions in GIS before using R.
as(s, "SpatialPointsDataFrame")
Do I get it right that for now it is better to stick with shapefiles to
read PolylineZM?
Mikhail
-- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster Weseler Stra?e 253, 48151 M?nster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebesma at wwu.de
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no
Roger: I see. It is not a 5-minute job. I'll leave my script as is with `shapefiles` package for now as it is working okay. I just have a feeling that shapefiles is getting quite outdated (last published in 2006) and overall trend is towards structured sp and maptools. Thanks for your help! Perhaps one day ZM support will be available in maptools/sp :-) P.S. I always thought and used M for route *m*easure data as a distance along the line via `Create Routes` tool in ArcGIS. I don't know how it can be non-standard. P.P.S. I used `Write Features to Text File` with `Samples` toolbox in ArcGIS. However I want to reduce number of steps overall and I thought I could use shapefiles directly. I would do everything in python with arcgisscripting module, but my script depends on `fda` and monotonic splines in R. Mikhail
-----Original Message----- From: Roger Bivand [mailto:Roger.Bivand at nhh.no] Sent: Monday, May 16, 2011 1:59 PM To: Mikhail Titov Cc: 'Edzer Pebesma'; r-sig-geo at r-project.org Subject: Re: [R-sig-Geo] How do I read/work with PolyLineZM with maptools/sp? On Mon, 16 May 2011, Mikhail Titov wrote:
Edzer: Thank you for your suggestions, but it doesn't help much. It does not recover either Z or M as attributes or anyhow else.
The Z is dropped for SpatialPolygons and SpatialLines everywhere. The M is not a standard part of the specification - it isn't obvious what it should be. You'd need to rewrite the C code in shapelib for maptools or rgdal to access these, and create a 4D object. Alternatively, try anything perhaps in Python with OGR to dump 3D points with M as an attribute, and a grouping factor to point to the feature ID in the DBF file. Roger
p <- as(s, "SpatialPointsDataFrame") names(p)
[1] "Id" "Lines.NR" "Lines.ID" "Line.NR"
slotNames(p)
[1] "data" "coords.nrs" "coords" "bbox" "proj4string"
head(p at coords)
coords.x1 coords.x2 [1,] 408794.5 4893921 [2,] 409088.3 4893599 [3,] 409165.2 4893484 [4,] 409434.7 4893214 [5,] 409684.9 4893060 [6,] 409742.6 4893060
head(p at data)
Id Lines.NR Lines.ID Line.NR 0 1 1 0 1 0.1 1 1 0 1 0.2 1 1 0 1 0.3 1 1 0 1 0.4 1 1 0 1 0.5 1 1 0 1
p$Z
NULL
p$z
NULL I double checked that I'm working with correct shapefile that has Z
values.
Mikhail
-----Original Message----- From: Edzer Pebesma [mailto:edzer.pebesma at uni-muenster.de] Sent: Monday, May 16, 2011 1:29 PM To: Mikhail Titov Cc: r-sig-geo at r-project.org Subject: Re: [R-sig-Geo] How do I read/work with PolyLineZM with maptools/sp? On 05/16/2011 08:22 PM, Mikhail Titov wrote:
I would try s$M and s$Z to access M and Z when they are attributes.
But what do I do when they are not? It can work for points, but not a
line as I can't have attributes for individual points of a line. I would prefer not to do any extra conversions in GIS before using R.
as(s, "SpatialPointsDataFrame")
Do I get it right that for now it is better to stick with shapefiles
to
read PolylineZM?
Mikhail
-- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster Weseler Stra?e 253, 48151 M?nster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebesma at wwu.de
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no
On Mon, 16 May 2011, Mikhail Titov wrote:
Roger: I see. It is not a 5-minute job. I'll leave my script as is with `shapefiles` package for now as it is working okay. I just have a feeling that shapefiles is getting quite outdated (last published in 2006) and overall trend is towards structured sp and maptools. Thanks for your help! Perhaps one day ZM support will be available in maptools/sp :-)
OGR says that it will not be returned: http://www.gdal.org/ogr/drv_shapefile.html
P.S. I always thought and used M for route *m*easure data as a distance along the line via `Create Routes` tool in ArcGIS. I don't know how it can be non-standard.
It always was a kludge. I guess that it could once have been intended to hold a precision value, but is not used as such systematically. The maptools interface could return it, but there is no structure to put it in, as it is data at the point level, not the feature level. It is not in accord with OGC SFS, I think. It could be an extra function returning any such file as a SpatialPointsDataFrame with Z, M, and FID data fields. The FID could then be used to link to the data in the DBF. Roger
P.P.S. I used `Write Features to Text File` with `Samples` toolbox in ArcGIS. However I want to reduce number of steps overall and I thought I could use shapefiles directly. I would do everything in python with arcgisscripting module, but my script depends on `fda` and monotonic splines in R. Mikhail
-----Original Message----- From: Roger Bivand [mailto:Roger.Bivand at nhh.no] Sent: Monday, May 16, 2011 1:59 PM To: Mikhail Titov Cc: 'Edzer Pebesma'; r-sig-geo at r-project.org Subject: Re: [R-sig-Geo] How do I read/work with PolyLineZM with maptools/sp? On Mon, 16 May 2011, Mikhail Titov wrote:
Edzer: Thank you for your suggestions, but it doesn't help much. It does not recover either Z or M as attributes or anyhow else.
The Z is dropped for SpatialPolygons and SpatialLines everywhere. The M is not a standard part of the specification - it isn't obvious what it should be. You'd need to rewrite the C code in shapelib for maptools or rgdal to access these, and create a 4D object. Alternatively, try anything perhaps in Python with OGR to dump 3D points with M as an attribute, and a grouping factor to point to the feature ID in the DBF file. Roger
p <- as(s, "SpatialPointsDataFrame") names(p)
[1] "Id" "Lines.NR" "Lines.ID" "Line.NR"
slotNames(p)
[1] "data" "coords.nrs" "coords" "bbox" "proj4string"
head(p at coords)
coords.x1 coords.x2 [1,] 408794.5 4893921 [2,] 409088.3 4893599 [3,] 409165.2 4893484 [4,] 409434.7 4893214 [5,] 409684.9 4893060 [6,] 409742.6 4893060
head(p at data)
Id Lines.NR Lines.ID Line.NR 0 1 1 0 1 0.1 1 1 0 1 0.2 1 1 0 1 0.3 1 1 0 1 0.4 1 1 0 1 0.5 1 1 0 1
p$Z
NULL
p$z
NULL I double checked that I'm working with correct shapefile that has Z
values.
Mikhail
-----Original Message----- From: Edzer Pebesma [mailto:edzer.pebesma at uni-muenster.de] Sent: Monday, May 16, 2011 1:29 PM To: Mikhail Titov Cc: r-sig-geo at r-project.org Subject: Re: [R-sig-Geo] How do I read/work with PolyLineZM with maptools/sp? On 05/16/2011 08:22 PM, Mikhail Titov wrote:
I would try s$M and s$Z to access M and Z when they are attributes.
But what do I do when they are not? It can work for points, but not a
line as I can't have attributes for individual points of a line. I would prefer not to do any extra conversions in GIS before using R.
as(s, "SpatialPointsDataFrame")
Do I get it right that for now it is better to stick with shapefiles
to
read PolylineZM?
Mikhail
-- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster Weseler Stra?e 253, 48151 M?nster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebesma at wwu.de
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no
Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no