Skip to content

Commit

Permalink
need to begin_wkt some how for #47
Browse files Browse the repository at this point in the history
  • Loading branch information
SymbolixAU committed Sep 11, 2019
1 parent d9b33d8 commit feefcd4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
2 changes: 1 addition & 1 deletion inst/include/geojsonsf/geojson/write_geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace write_geometry {
SEXP sfg = sfc[ sfg_index ];

std::string geom_type;
Rcpp::CharacterVector cls = sfheaders::getSfClass(sfg);
Rcpp::CharacterVector cls = sfheaders::sfc::getSfClass(sfg);
cls_check( cls );
geom_type = cls[1];

Expand Down
2 changes: 1 addition & 1 deletion src/geojson_to_wkt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void parse_geometry_object_wkt(

std::ostringstream os;
Rcpp::StringVector wkt;
begin_wkt(os, geom_type);
//begin_wkt(os, geom_type);

if (geom_type == "Point") {
point_to_wkt(os, coord_array);
Expand Down
51 changes: 39 additions & 12 deletions src/geojson_wkt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,38 @@

using namespace rapidjson;

std::string wkt_dim( int n ) {
switch( n ) {
case 3: {
return " Z";
}
case 4: {
return " ZM";
}
default: {
return "";
}
}
}

void begin_wkt(std::ostringstream& os, std::string& geom_type) {
//std::string dim = wkt_dim( n_coords );
std::string dim = wkt_dim(0);

if (geom_type == "Point") {
os << "POINT (";
os << "POINT" << dim << " (";
} else if (geom_type == "MultiPoint") {
os << "MULTIPOINT ((";
os << "MULTIPOINT" << dim << " ((";
} else if (geom_type == "LineString") {
os << "LINESTRING (";
os << "LINESTRING" << dim << " (";
} else if (geom_type == "MultiLineString") {
os << "MULTILINESTRING ((";
os << "MULTILINESTRING" << dim << " ((";
} else if (geom_type == "Polygon") {
os << "POLYGON ((";
os << "POLYGON" << dim << " ((";
} else if (geom_type == "MultiPolygon") {
os << "MULTIPOLYGON (((";
os << "MULTIPOLYGON" << dim << " (((";
} else if (geom_type == "GeometryCollection") {
os << "GEOMETRYCOLLECTION (";
os << "GEOMETRYCOLLECTION" << dim << " (";
}
}

Expand Down Expand Up @@ -67,16 +83,27 @@ void polygon_separate_wkt(std::ostringstream& os, int i, int n) {
}
}

void add_coordinate_to_wkt_stream(std::ostringstream& os, double coord ) {
os << coord;
}

void add_lonlat_to_wkt_stream(std::ostringstream& os, float lon, float lat ) {
void add_lonlat_to_wkt_stream(std::ostringstream& os, double lon, double lat ) {
os << lon << " " << lat;
}

void point_to_wkt(std::ostringstream& os, const Value& coord_array) {
Rcpp::NumericVector point(2);
point[0] = geojsonsf::sfg::get_lon(coord_array);
point[1] = geojsonsf::sfg::get_lat(coord_array);
add_lonlat_to_wkt_stream(os, point[0], point[1]);
int n = coord_array.Size();
int i;
for( i = 0; i < n; i++ ) {
if( i > 0 ) {
os << " ";
}
add_coordinate_to_wkt_stream( os, coord_array[i].GetDouble() );
}
// Rcpp::NumericVector point(2);
// point[0] = geojsonsf::sfg::get_lon(coord_array);
// point[1] = geojsonsf::sfg::get_lat(coord_array);
// add_lonlat_to_wkt_stream(os, point[0], point[1]);
}


Expand Down

0 comments on commit feefcd4

Please sign in to comment.