本文整理汇总了C++中SpatialReference类的典型用法代码示例。如果您正苦于以下问题:C++ SpatialReference类的具体用法?C++ SpatialReference怎么用?C++ SpatialReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SpatialReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NODE_ARG_OBJECT
Handle<Value> Geometry::createFromWkb(const Arguments &args)
{
HandleScope scope;
std::string wkb_string;
SpatialReference *srs = NULL;
Handle<Object> wkb_obj;
NODE_ARG_OBJECT(0, "wkb", wkb_obj);
NODE_ARG_WRAPPED_OPT(1, "srs", SpatialReference, srs);
std::string obj_type = TOSTR(wkb_obj->GetConstructorName());
if(obj_type != "Buffer"){
return NODE_THROW("Argument must be a buffer object");
}
unsigned char* data = (unsigned char *) Buffer::Data(wkb_obj);
size_t length = Buffer::Length(wkb_obj);
OGRGeometry *geom = NULL;
OGRSpatialReference *ogr_srs = NULL;
if (srs) {
ogr_srs = srs->get();
}
OGRErr err = OGRGeometryFactory::createFromWkb(data, ogr_srs, &geom, length);
if (err) {
return NODE_THROW_OGRERR(err);
}
return scope.Close(Geometry::New(geom, true));
}
示例2: tolua_Lua_ScriptEngine_tolua_SpatialReference_getGeographicSRS00
/* method: getGeographicSRS of class SpatialReference */
static int tolua_Lua_ScriptEngine_tolua_SpatialReference_getGeographicSRS00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"SpatialReference",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
SpatialReference* self = (SpatialReference*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'getGeographicSRS'",NULL);
#endif
{
SpatialReference* tolua_ret = (SpatialReference*) self->getGeographicSRS();
tolua_pushusertype(tolua_S,(void*)tolua_ret,"SpatialReference");
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'getGeographicSRS'.",&tolua_err);
return 0;
#endif
}
示例3: transform
Polygon Polygon::transform(const SpatialReference& ref) const
{
if (m_srs.empty())
throw pdal_error("Polygon::transform failed due to m_srs being empty");
if (ref.empty())
throw pdal_error("Polygon::transform failed due to ref being empty");
gdal::SpatialRef fromRef(m_srs.getWKT());
gdal::SpatialRef toRef(ref.getWKT());
gdal::Geometry geom(wkt(12, true), fromRef);
geom.transform(toRef);
return Polygon(geom.wkt(), ref, m_ctx);
}
示例4: transformWkt
std::string transformWkt(std::string wkt, const SpatialReference& from,
const SpatialReference& to)
{
//ABELL - Should this throw? Return empty string?
if (from.empty() || to.empty())
return wkt;
gdal::SpatialRef fromRef(from.getWKT());
gdal::SpatialRef toRef(to.getWKT());
gdal::Geometry geom(wkt, fromRef);
geom.transform(toRef);
return geom.wkt();
}
示例5: toPTree
inline ptree toPTree(const SpatialReference& ref)
{
ptree srs;
srs.put("proj4", ref.getProj4());
srs.put("prettywkt", ref.getWKT(SpatialReference::eHorizontalOnly, true));
srs.put("wkt", ref.getWKT(SpatialReference::eHorizontalOnly, false));
srs.put("compoundwkt", ref.getWKT(SpatialReference::eCompoundOK, false));
srs.put("prettycompoundwkt", ref.getWKT(SpatialReference::eCompoundOK,
true));
return srs;
}
示例6: position
void StatsFilter::extractMetadata(PointTableRef table)
{
uint32_t position(0);
for (auto di = m_stats.begin(); di != m_stats.end(); ++di)
{
const Summary& s = di->second;
MetadataNode t = m_metadata.addList("statistic");
t.add("position", position++);
s.extractMetadata(t);
}
// If we have X, Y, & Z dims, output bboxes
auto xs = m_stats.find(Dimension::Id::X);
auto ys = m_stats.find(Dimension::Id::Y);
auto zs = m_stats.find(Dimension::Id::Z);
if (xs != m_stats.end() &&
ys != m_stats.end() &&
zs != m_stats.end())
{
BOX3D box(xs->second.minimum(), ys->second.minimum(), zs->second.minimum(),
xs->second.maximum(), ys->second.maximum(), zs->second.maximum());
pdal::Polygon p(box);
MetadataNode mbox = Utils::toMetadata(box);
MetadataNode box_metadata = m_metadata.add("bbox");
MetadataNode metadata = box_metadata.add("native");
MetadataNode boundary = metadata.add("boundary", p.json());
MetadataNode bbox = metadata.add(mbox);
SpatialReference ref = table.anySpatialReference();
// if we don't get an SRS from the PointTableRef,
// we won't add another metadata node
if (!ref.empty())
{
p.setSpatialReference(ref);
SpatialReference epsg4326("EPSG:4326");
pdal::Polygon pdd = p.transform(epsg4326);
BOX3D ddbox = pdd.bounds();
MetadataNode epsg_4326_box = Utils::toMetadata(ddbox);
MetadataNode dddbox = box_metadata.add("EPSG:4326");
dddbox.add(epsg_4326_box);
MetadataNode ddboundary = dddbox.add("boundary", pdd.json());
}
}
}
示例7: setSpatialReference
void Stage::setSpatialReference(MetadataNode& m,
const SpatialReference& spatialRef)
{
m_spatialReference = spatialRef;
auto pred = [](MetadataNode m){ return m.name() == "spatialreference"; };
MetadataNode spatialNode = m.findChild(pred);
if (spatialNode.empty())
{
m.add(spatialRef.toMetadata());
m.add("spatialreference", spatialRef.getWKT(), "SRS of this stage");
m.add("comp_spatialreference", spatialRef.getWKT(),
"SRS of this stage");
}
}
示例8: OSRNewSpatialReference
SpatialReference* SpatialReference::createFromPROJ4(
const std::string& proj4, const std::string& alias, const std::string& name)
{
SpatialReference* result = NULL;
//GDAL_SCOPED_LOCK;
void* handle = OSRNewSpatialReference( NULL );
if ( OSRImportFromProj4( handle, proj4.c_str() ) == OGRERR_NONE )
{
result = new SpatialReference( handle, "PROJ4", alias, name );
result->Init();
}
else
{
OSRDestroySpatialReference( handle );
}
return result;
}
示例9: setSpatialReference
void Stage::setSpatialReference(MetadataNode& m,
const SpatialReference& spatialRef)
{
m_spatialReference = spatialRef;
auto pred = [](MetadataNode m){ return m.name() == "spatialreference"; };
MetadataNode spatialNode = m.findChild(pred);
if (spatialNode.empty())
{
m.add(Utils::toMetadata(spatialRef));
m.add("spatialreference",
spatialRef.getWKT(SpatialReference::eHorizontalOnly, false),
"SRS of this stage");
m.add("comp_spatialreference",
spatialRef.getWKT(SpatialReference::eCompoundOK, false),
"SRS of this stage");
}
}
示例10: findVlr
void LasHeader::setSrsFromGeotiff()
{
LasVLR *vlr;
uint8_t *data;
size_t dataLen;
vlr = findVlr(TRANSFORM_USER_ID, GEOTIFF_DIRECTORY_RECORD_ID);
// We must have a directory entry.
if (!vlr)
return;
data = (uint8_t *)vlr->data();
dataLen = vlr->dataLen();
std::vector<uint8_t> directoryRec(data, data + dataLen);
vlr = findVlr(TRANSFORM_USER_ID, GEOTIFF_DOUBLES_RECORD_ID);
data = NULL;
dataLen = 0;
if (vlr && !vlr->isEmpty())
{
data = (uint8_t *)vlr->data();
dataLen = vlr->dataLen();
}
std::vector<uint8_t> doublesRec(data, data + dataLen);
vlr = findVlr(TRANSFORM_USER_ID, GEOTIFF_ASCII_RECORD_ID);
data = NULL;
dataLen = 0;
if (vlr && !vlr->isEmpty())
{
data = (uint8_t *)vlr->data();
dataLen = vlr->dataLen();
}
std::vector<uint8_t> asciiRec(data, data + dataLen);
GeotiffSrs geotiff(directoryRec, doublesRec, asciiRec);
SpatialReference gtiffSrs = geotiff.srs();
if (!gtiffSrs.empty())
m_srs = gtiffSrs;
}
示例11: TEST
TEST(LasWriterTest, fix1063_1064_1065)
{
std::string outfile = Support::temppath("out.las");
std::string infile = Support::datapath("las/test1_4.las");
FileUtils::deleteFile(outfile);
std::string cmd = "pdal translate --writers.las.forward=all "
"--writers.las.a_srs=\"EPSG:4326\" " + infile + " " + outfile;
std::string output;
Utils::run_shell_command(Support::binpath(cmd), output);
Options o;
o.add("filename", outfile);
LasReader r;
r.setOptions(o);
PointTable t;
r.prepare(t);
PointViewSet s = r.execute(t);
EXPECT_EQ(s.size(), 1u);
PointViewPtr v = *s.begin();
EXPECT_EQ(v->size(), 1000u);
// https://github.com/PDAL/PDAL/issues/1063
for (PointId idx = 0; idx < v->size(); ++idx)
EXPECT_EQ(8, v->getFieldAs<int>(Dimension::Id::ClassFlags, idx));
// https://github.com/PDAL/PDAL/issues/1064
MetadataNode m = r.getMetadata();
m = m.findChild("global_encoding");
EXPECT_EQ(17, m.value<int>());
// https://github.com/PDAL/PDAL/issues/1065
SpatialReference ref = v->spatialReference();
std::string wkt = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]";
EXPECT_EQ(ref.getWKT(), wkt);
}
示例12: OSRNewSpatialReference
bool SpatialReference::equals(const SpatialReference& input) const
{
OGRSpatialReferenceH current =
OSRNewSpatialReference(getWKT(eCompoundOK, false).c_str());
OGRSpatialReferenceH other =
OSRNewSpatialReference(input.getWKT(eCompoundOK, false).c_str());
int output = OSRIsSame(current, other);
OSRDestroySpatialReference(current);
OSRDestroySpatialReference(other);
return (output == 1);
}
示例13: tolua_Lua_ScriptEngine_tolua_SpatialReference_transform00
/* method: transform of class SpatialReference */
static int tolua_Lua_ScriptEngine_tolua_SpatialReference_transform00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"SpatialReference",0,&tolua_err) ||
!tolua_isusertype(tolua_S,2,"GeoPoint",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
SpatialReference* self = (SpatialReference*) tolua_tousertype(tolua_S,1,0);
GeoPoint in = *((GeoPoint*) tolua_tousertype(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'transform'",NULL);
#endif
{
GeoPoint tolua_ret = (GeoPoint) self->transform(in);
{
#ifdef __cplusplus
void* tolua_obj = new GeoPoint(tolua_ret);
tolua_pushusertype(tolua_S,tolua_clone(tolua_S,tolua_obj,tolua_collect_GeoPoint),"GeoPoint");
#else
void* tolua_obj = tolua_copy(tolua_S,(void*)&tolua_ret,sizeof(GeoPoint));
tolua_pushusertype(tolua_S,tolua_clone(tolua_S,tolua_obj,tolua_collect),"GeoPoint");
#endif
}
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'transform'.",&tolua_err);
return 0;
#endif
}
示例14: NODE_ARG_STR
Handle<Value> Geometry::createFromWkt(const Arguments &args)
{
HandleScope scope;
std::string wkt_string;
SpatialReference *srs = NULL;
NODE_ARG_STR(0, "wkt", wkt_string);
NODE_ARG_WRAPPED_OPT(1, "srs", SpatialReference, srs);
char *wkt = (char*) wkt_string.c_str();
OGRGeometry *geom = NULL;
OGRSpatialReference *ogr_srs = NULL;
if (srs) {
ogr_srs = srs->get();
}
OGRErr err = OGRGeometryFactory::createFromWkt(&wkt, ogr_srs, &geom);
if (err) {
return NODE_THROW_OGRERR(err);
}
return scope.Close(Geometry::New(geom, true));
}
示例15: addWktVlr
/// Add a Well-known Text VLR associated with the spatial reference.
/// \param srs - Associated spatial reference.
/// \return Whether the VLR was added.
bool LasWriter::addWktVlr(const SpatialReference& srs)
{
std::string wkt = srs.getWKT(SpatialReference::eCompoundOK);
if (wkt.empty())
return false;
std::vector<uint8_t> wktBytes(wkt.begin(), wkt.end());
// This tacks a NULL to the end of the data, which is required by the spec.
wktBytes.resize(wktBytes.size() + 1, 0);
addVlr(TRANSFORM_USER_ID, WKT_RECORD_ID, "OGC Tranformation Record",
wktBytes);
// The data in the vector gets moved to the VLR, so we have to recreate it.
std::vector<uint8_t> wktBytes2(wkt.begin(), wkt.end());
wktBytes2.resize(wktBytes2.size() + 1, 0);
addVlr(LIBLAS_USER_ID, WKT_RECORD_ID,
"OGR variant of OpenGIS WKT SRS", wktBytes2);
return true;
}