% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/drop_null_coords.R
\name{drop_null_coords}
\alias{drop_null_coords}
\title{Drop any NULL coordinates from a GeoJSON geometry.}
\usage{
drop_null_coords(x)
}
\arguments{
\item{x}{A GeoJSON geometry parsed as nested list.
E.g. \code{geo_gj$path_location_path_gps}.}
}
\value{
The nested list minus the last element (if NULL).
}
\description{
This helper patches a bug/feature in ODK Central (versions 0.7-0.9), where
geotrace / geoshape GeoJSON contains a last coordinate pair with NULL
lat/lon (no alt/acc), and WKT ends in \verb{, undefined NaN}.
}
\details{
While \code{\link{split_geotrace}} and \code{\link{split_geoshape}} modify
the WKT inline, it is more maintainable to separate the GeoJSON cleaner
into this function.

This helper drops the last element of a GeoJSON coordinate list if it is
\code{list(NULL, NULL)}.
}
\examples{
# A snapshot of geo data with trailing empty coordinates.
data("geo_gj88")

len_coords <- length(geo_gj88$path_location_path_gps[[1]]$coordinates)

length(geo_gj88$path_location_path_gps[[1]]$coordinates[[len_coords]]) \%>\%
  testthat::expect_equal(2)

geo_gj88$path_location_path_gps[[1]]$coordinates[[len_coords]][[1]] \%>\%
  testthat::expect_null()

geo_gj88$path_location_path_gps[[1]]$coordinates[[len_coords]][[2]] \%>\%
  testthat::expect_null()

# The last coordinate pair is a list(NULL, NULL).
# Invalid coordinates like these are a choking hazard for geospatial
# packages. We should remove them before we can convert ODK data into native
# spatial formats, such as sf.
str(geo_gj88$path_location_path_gps[[1]]$coordinates[[len_coords]])

geo_gj_repaired <- geo_gj88 \%>\%
  dplyr::mutate(
    path_location_path_gps = path_location_path_gps \%>\%
      purrr::map(drop_null_coords)
  )

len_coords_repaired <- length(
  geo_gj_repaired$path_location_path_gps[[1]]$coordinates
)
testthat::expect_equal(len_coords_repaired + 1, len_coords)
}
\seealso{
Other utilities: 
\code{\link{attachment_get}()},
\code{\link{attachment_link}()},
\code{\link{attachment_url}()},
\code{\link{form_schema_parse}()},
\code{\link{get_one_attachment}()},
\code{\link{get_one_submission}()},
\code{\link{get_one_submission_att_list}()},
\code{\link{get_one_submission_audit}()},
\code{\link{handle_ru_attachments}()},
\code{\link{handle_ru_datetimes}()},
\code{\link{handle_ru_geopoints}()},
\code{\link{handle_ru_geoshapes}()},
\code{\link{handle_ru_geotraces}()},
\code{\link{isodt_to_local}()},
\code{\link{odata_submission_rectangle}()},
\code{\link{predict_ruodk_name}()},
\code{\link{prepend_uuid}()},
\code{\link{split_geopoint}()},
\code{\link{split_geoshape}()},
\code{\link{split_geotrace}()},
\code{\link{strip_uuid}()},
\code{\link{tidyeval}},
\code{\link{unnest_all}()}
}
\concept{utilities}
