R/SA-methods.R

Defines functions as.SpatialPoints.SaSamplingPoint parseSamplingPoint SaSamplingSurface SaSamplingPoint

Documented in as.SpatialPoints.SaSamplingPoint parseSamplingPoint SaSamplingPoint SaSamplingPoint SaSamplingSurface

############################################################################## #
# Copyright (C) 2019 by 52 North                                               #
# Initiative for Geospatial Open Source Software GmbH                          #
#                                                                              #
# Contact: Andreas Wytzisk                                                     #
# 52 North Initiative for Geospatial Open Source Software GmbH                 #
# Martin-Luther-King-Weg 24                                                    #
# 48155 Muenster, Germany                                                      #
# info@52north.org                                                             #
#                                                                              #
# This program is free software; you can redistribute and/or modify it under   #
# the terms of the GNU General Public License version 2 as published by the    #
# Free Software Foundation.                                                    #
#                                                                              #
# This program is distributed WITHOUT ANY WARRANTY; even without the implied   #
# WARRANTY OF MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
# General Public License for more details.                                     #
#                                                                              #
# You should have received a copy of the GNU General Public License along with #
# this program (see gpl-2.0.txt). If not, write to the Free Software           #
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA or #
# visit the Free Software Foundation web page, http://www.fsf.org.             #
#                                                                              #
# Author: Daniel Nuest (daniel.nuest@uni-muenster.de)                          #
# Created: 2010-09-09                                                          #
# Project: sos4R - https://github.com/52North/sos4R                            #
#                                                                              #
############################################################################## #

#
# construction methods ----
#
SaSamplingPoint <- function(sampledFeatures,
                            position,
                            relatedObservation = list(NA),
                            relatedSamplingFeature = list(NA),
                            surveyDetails = NA,
                            id = NA_character_) {
  new("SaSamplingPoint", sampledFeatures = sampledFeatures,
      position = position, relatedObservation = relatedObservation,
      surveyDetails = surveyDetails, id = id)
}

SaSamplingSurface <- function(sampledFeatures,
                              shape,
                              relatedObservation = list(NA),
                              relatedSamplingFeature = list(NA),
                              surveyDetails = NA,
                              position = NA) {
  new("SaSamplingSurface", sampledFeatures = sampledFeatures,
      shape = shape, relatedObservation = relatedObservation,
      relatedSamplingFeature = relatedSamplingFeature,
      surveyDetails = surveyDetails, position = position)
}

#
# parsing ----
#
parseSamplingPoint <- function(obj, sos) {
  sampledFeatures <- as.list(xml2::xml_text(
    xml2::xml_find_first(x = obj, xpath = gmlNameName, ns = sos@namespaces))
  )
  positionXml <- xml2::xml_child(x = obj, search = saPositionName, ns = sos@namespaces)
  position <- parsePosition(positionXml, sos = sos)
  id <- xml2::xml_attr(x = obj, attr = "id", default = NA_character_)

  sp <- SaSamplingPoint(sampledFeatures = sampledFeatures, position = position, id = id)
  return(sp)
}

#
# coercion methods ----
#
as.SpatialPoints.SaSamplingPoint = function(from) {
  as(from@position, "SpatialPoints")
}
setAs(from = "SaSamplingPoint", to = "SpatialPoints",
      def = function(from) {
        as.SpatialPoints.SaSamplingPoint(from)
      }
)
setAs(from = "SaSamplingPoint", to = "Spatial",
      def = function(from) {
        as.SpatialPoints.SaSamplingPoint(from)
      }
)
52North/sos4R documentation built on Jan. 30, 2021, 11:42 p.m.