void object::test<1>() { // POINT(1.234 5.678) std::string wkt("POINT (1.234 5.678)"); std::string wkb("01010000005839B4C876BEF33F83C0CAA145B61640"); test_wkb(wkb, wkt); }
void object::test<2>() { // SRID=4;POINT(0 0) std::string wkt("POINT(0 0)"); std::string ewkb("01010000200400000000000000000000000000000000000000"); test_wkb(ewkb, wkt); }
void object::test<4>() { // POINT (1.234 5.678 15 79) -- XYZM std::string wkt("POINT (1.234 5.678 15 79)"); std::string ewkb("01010000C05839B4C876BEF33F83C0CAA145B616400000000000002E400000000000C05340"); test_wkb(ewkb, wkt); }
void object::test<3>() { // SRID=32632;POINT(1.234 5.678) std::string wkt("POINT (1.234 5.678)"); std::string ewkb("0101000020787F00005839B4C876BEF33F83C0CAA145B61640"); test_wkb(ewkb, wkt); }
template<> NValue NValue::callUnary<FUNC_VOLT_POINTFROMTEXT>() const { if (isNull()) { return NValue::getNullValue(VALUE_TYPE_POINT); } int32_t textLength; const char* textData = getObject_withoutNull(&textLength); std::string wkt(textData, textLength); // Discard whitespace, but return commas or parentheses as tokens Tokenizer tokens(wkt, boost::char_separator<char>(" \f\n\r\t\v", ",()")); Tokenizer::iterator it = tokens.begin(); Tokenizer::iterator end = tokens.end(); if (! boost::iequals(*it, "point")) { throwInvalidWktPoint(wkt); } ++it; if (! boost::iequals(*it, "(")) { throwInvalidWktPoint(wkt); } ++it; GeographyPointValue::Coord lng = stringToCoord(POINT, wkt, *it); ++it; GeographyPointValue::Coord lat = stringToCoord(POINT, wkt, *it); ++it; if ( lng < -180.0 || lng > 180.0) { throwInvalidPointLongitude(wkt); } if (lat < -90.0 || lat > 90.0 ) { throwInvalidPointLatitude(wkt); } if (! boost::iequals(*it, ")")) { throwInvalidWktPoint(wkt); } ++it; if (it != end) { throwInvalidWktPoint(wkt); } NValue returnValue(VALUE_TYPE_POINT); returnValue.getGeographyPointValue() = GeographyPointValue(lng, lat); return returnValue; }
Handle<Value> Geometry::FromWKT(const Arguments& args) { Geometry *geom = ObjectWrap::Unwrap<Geometry>(args.This()); HandleScope scope; String::AsciiValue wkt(args[0]->ToString()); bool r = geom->FromWKT(*wkt); if (!r) { return ThrowException(String::New("invalid WKT")); } return Undefined(); }
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); }
Handle<Value> Geometry::New(const Arguments& args) { Geometry *geom; HandleScope scope; if (args.Length() == 0) { geom = new Geometry(); } else if (args.Length() == 1 && args[0]->IsString()) { String::Utf8Value wkt(args[0]->ToString()); geom = new Geometry(*wkt); } geom->Wrap(args.This()); return args.This(); }
void object::test<2>() { ensure("SRS handle is NULL", NULL != srs_); std::string wkt("+proj=lcc +x_0=0.6096012192024384e+06 +y_0=0" "+lon_0=90dw +lat_0=42dn +lat_1=44d4'n +lat_2=42d44'n" "+a=6378206.400000 +rf=294.978698 +nadgrids=conus,ntv1_can.dat"); err_ = OSRImportFromProj4(srs_, wkt.c_str()); ensure_equals("OSRImportFromProj4)( failed", err_, OGRERR_NONE); const double maxError = 0.0005; double val = 0; val = OSRGetProjParm(srs_, SRS_PP_FALSE_EASTING, -1111, &err_); ensure_equals("OSRGetProjParm() failed", err_, OGRERR_NONE); ensure("Parsing exponents not supported", std::fabs(val - 609601.219) <= maxError); }
std::string Polygon::json(double precision) const { std::ostringstream prec; prec << precision; char **papszOptions = NULL; papszOptions = CSLSetNameValue(papszOptions, "COORDINATE_PRECISION", prec.str().c_str() ); std::string w(wkt()); gdal::SpatialRef srs(m_srs.getWKT(pdal::SpatialReference::eCompoundOK)); gdal::Geometry g(w, srs); char* json = OGR_G_ExportToJsonEx(g.get(), papszOptions); std::string output(json); OGRFree(json); return output; }
void object::test<1>() { ensure("SRS handle is NULL", NULL != srs_); std::string wkt("+proj=tmerc +lat_0=53.5000000000 +lon_0=-8.0000000000" "+k_0=1.0000350000 +x_0=200000.0000000000 +y_0=250000.0000000000" "+a=6377340.189000 +rf=299.324965 +towgs84=482.530," "-130.596,564.557,-1.042,-0.214,-0.631,8.15"); err_ = OSRImportFromProj4(srs_, wkt.c_str()); ensure_equals("OSRImportFromProj4)( failed", err_, OGRERR_NONE); // TODO: Check max error value const double maxError = 0.00005; // 0.0000005 double val = 0; val = OSRGetProjParm(srs_, SRS_PP_SCALE_FACTOR, -1111, &err_); ensure_equals("OSRGetProjParm() failed", err_, OGRERR_NONE); ensure("+k_0 not supported on import from PROJ.4", std::fabs(val - 1.000035) <= maxError); }
bool empty() const { return wkt().empty(); }
void object::test<5>() { std::string wkt("MULTIPOINT (1.123 1.456, 2.123 2.456, 3.123 3.456)"); std::string ewkb("01040000000300000001010000002b8716d9cef7f13fb29defa7c64bf73f010100000096438b6ce7fb0040d9cef753e3a50340010100000096438b6ce7fb0840d9cef753e3a50b40"); test_wkb(ewkb, wkt); }
ossimProjection* ossimGdalProjectionFactory::createProjection(const ossimFilename& filename, ossim_uint32 entryIdx)const { ossimKeywordlist kwl; if(ossimString(filename).trim().empty()) return 0; // ossimRefPtr<ossimImageHandler> h = new ossimGdalTileSource; GDALDatasetH h = GDALOpen(filename.c_str(), GA_ReadOnly); GDALDriverH driverH = 0; ossimProjection* proj = 0; if(h) { driverH = GDALGetDatasetDriver( h ); ossimString driverName( driverH ? GDALGetDriverShortName( driverH ) : "" ); // use OSSIM's projection loader for NITF // if(driverName == "NITF") { GDALClose(h); return 0; } if(entryIdx != 0) { char** papszMetadata = GDALGetMetadata( h, "SUBDATASETS" ); //--- // ??? (drb) Should this be: // if ( entryIdx >= CSLCount(papszMetadata) ) close... //--- if( papszMetadata&&(CSLCount(papszMetadata) < static_cast<ossim_int32>(entryIdx)) ) { ossimNotify(ossimNotifyLevel_WARN) << "ossimGdalProjectionFactory::createProjection: We don't support multi entry handlers through the factory yet, only through the handler!"; GDALClose(h); return 0; } else { GDALClose(h); return 0; } } ossimString wkt(GDALGetProjectionRef( h )); double geoTransform[6]; bool transOk = GDALGetGeoTransform( h, geoTransform ) == CE_None; bool wktTranslatorOk = wkt.empty()?false:wktTranslator.toOssimKwl(wkt, kwl); if(!wktTranslatorOk) { ossim_uint32 gcpCount = GDALGetGCPCount(h); if(gcpCount > 3) { ossim_uint32 idx = 0; const GDAL_GCP* gcpList = GDALGetGCPs(h); ossimTieGptSet tieSet; if(gcpList) { for(idx = 0; idx < gcpCount; ++idx) { ossimDpt dpt(gcpList[idx].dfGCPPixel, gcpList[idx].dfGCPLine); ossimGpt gpt(gcpList[idx].dfGCPY, gcpList[idx].dfGCPX, gcpList[idx].dfGCPZ); tieSet.addTiePoint(new ossimTieGpt(gpt, dpt, .5)); } //ossimPolynomProjection* tempProj = new ossimPolynomProjection; ossimBilinearProjection* tempProj = new ossimBilinearProjection; //tempProj->setupOptimizer("1 x y x2 xy y2 x3 y3 xy2 x2y z xz yz"); tempProj->optimizeFit(tieSet); proj = tempProj; } } } if ( transOk && proj==0 ) { ossimString proj_type(kwl.find(ossimKeywordNames::TYPE_KW)); ossimString datum_type(kwl.find(ossimKeywordNames::DATUM_KW)); ossimString units(kwl.find(ossimKeywordNames::UNITS_KW)); if ( proj_type.trim().empty() && (driverName == "MrSID" || driverName == "JP2MrSID") ) { bool bClose = true; // ESH 04/2008, #54: if no rotation factors use geographic system if( geoTransform[2] == 0.0 && geoTransform[4] == 0.0 ) { ossimString projTag( GDALGetMetadataItem( h, "IMG__PROJECTION_NAME", "" ) ); if ( projTag.contains("Geographic") ) { bClose = false; kwl.add(ossimKeywordNames::TYPE_KW, "ossimEquDistCylProjection", true); proj_type = kwl.find( ossimKeywordNames::TYPE_KW ); // Assign units if set in Metadata ossimString unitTag( GDALGetMetadataItem( h, "IMG__HORIZONTAL_UNITS", "" ) ); if ( unitTag.contains("dd") ) // decimal degrees { units = "degrees"; } else if ( unitTag.contains("dm") ) // decimal minutes { units = "minutes"; } else if ( unitTag.contains("ds") ) // decimal seconds { units = "seconds"; } } } if ( bClose == true ) { GDALClose(h); return 0; } } // Pixel-is-point of pixel-is area affects the location of the tiepoint since OSSIM is // always pixel-is-point so 1/2 pixel shift may be necessary: if((driverName == "MrSID") || (driverName == "JP2MrSID") || (driverName == "AIG")) { const char* rasterTypeStr = GDALGetMetadataItem( h, "GEOTIFF_CHAR__GTRasterTypeGeoKey", "" ); ossimString rasterTypeTag( rasterTypeStr ); // If the raster type is pixel_is_area, shift the tie point by // half a pixel to locate it at the pixel center. if ((driverName == "AIG") || (rasterTypeTag.contains("RasterPixelIsArea"))) { geoTransform[0] += fabs(geoTransform[1]) / 2.0; geoTransform[3] -= fabs(geoTransform[5]) / 2.0; } } else { // Conventionally, HFA stores the pixel alignment type for each band. Here assume all // bands are the same. Consider only the first band: GDALRasterBandH bBand = GDALGetRasterBand( h, 1 ); char** papszMetadata = GDALGetMetadata( bBand, NULL ); if (CSLCount(papszMetadata) > 0) { for(int i = 0; papszMetadata[i] != NULL; i++ ) { ossimString metaStr = papszMetadata[i]; metaStr.upcase(); if (metaStr.contains("AREA_OR_POINT")) { ossimString pixel_is_point_or_area = metaStr.split("=")[1]; pixel_is_point_or_area.upcase(); if (pixel_is_point_or_area.contains("AREA")) { // Need to shift the tie point so that pixel is point: geoTransform[0] += fabs(geoTransform[1]) / 2.0; geoTransform[3] -= fabs(geoTransform[5]) / 2.0; } break; } } } } kwl.remove(ossimKeywordNames::UNITS_KW); ossimDpt gsd(fabs(geoTransform[1]), fabs(geoTransform[5])); ossimDpt tie(geoTransform[0], geoTransform[3]); ossimUnitType savedUnitType = static_cast<ossimUnitType>(ossimUnitTypeLut::instance()->getEntryNumber(units)); ossimUnitType unitType = savedUnitType; if(unitType == OSSIM_UNIT_UNKNOWN) unitType = OSSIM_METERS; if((proj_type == "ossimLlxyProjection") || (proj_type == "ossimEquDistCylProjection")) { // ESH 09/2008 -- Add the orig_lat and central_lon if the image // is using geographic coordsys. This is used to convert the // gsd to linear units. // Half the number of pixels in lon/lat directions int nPixelsLon = GDALGetRasterXSize(h)/2.0; int nPixelsLat = GDALGetRasterYSize(h)/2.0; // Shift from image corner to center in lon/lat double shiftLon = nPixelsLon * fabs(gsd.x); double shiftLat = -nPixelsLat * fabs(gsd.y); // lon/lat of center pixel of the image double centerLon = tie.x + shiftLon; double centerLat = tie.y + shiftLat; kwl.add(ossimKeywordNames::ORIGIN_LATITUDE_KW, centerLat, true); kwl.add(ossimKeywordNames::CENTRAL_MERIDIAN_KW, centerLon, true); kwl.add(ossimKeywordNames::TIE_POINT_LAT_KW, tie.y, true); kwl.add(ossimKeywordNames::TIE_POINT_LON_KW, tie.x, true); kwl.add(ossimKeywordNames::DECIMAL_DEGREES_PER_PIXEL_LAT, gsd.y, true); kwl.add(ossimKeywordNames::DECIMAL_DEGREES_PER_PIXEL_LON, gsd.x, true); if(savedUnitType == OSSIM_UNIT_UNKNOWN) { unitType = OSSIM_DEGREES; } } kwl.add(ossimKeywordNames::PIXEL_SCALE_XY_KW, gsd.toString(), true); kwl.add(ossimKeywordNames::PIXEL_SCALE_UNITS_KW, units, true); kwl.add(ossimKeywordNames::TIE_POINT_XY_KW, tie.toString(), true); kwl.add(ossimKeywordNames::TIE_POINT_UNITS_KW, units, true); std::stringstream mString; // store as a 4x4 matrix mString << ossimString::toString(geoTransform[1], 20) << " " << ossimString::toString(geoTransform[2], 20) << " " << 0 << " " << ossimString::toString(geoTransform[0], 20) << " " << ossimString::toString(geoTransform[4], 20) << " " << ossimString::toString(geoTransform[5], 20) << " " << 0 << " " << ossimString::toString(geoTransform[3], 20) << " " << 0 << " " << 0 << " " << 1 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 1; kwl.add(ossimKeywordNames::IMAGE_MODEL_TRANSFORM_MATRIX_KW, mString.str().c_str(), true); //--- // SPECIAL CASE: ArcGrid in British National Grid //--- if(driverName == "AIG" && datum_type == "OSGB_1936") { ossimFilename prj_file = filename.path() + "/prj.adf"; if(prj_file.exists()) { ossimKeywordlist prj_kwl(' '); prj_kwl.addFile(prj_file); ossimString proj = prj_kwl.find("Projection"); // Reset projection and Datum correctly for BNG. if(proj.upcase().contains("GREATBRITAIN")) { kwl.add(ossimKeywordNames::TYPE_KW, "ossimBngProjection", true); ossimString datum = prj_kwl.find("Datum"); if(datum != "") { if(datum == "OGB_A") datum = "OGB-A"; else if(datum == "OGB_B") datum = "OGB-B"; else if(datum == "OGB_C") datum = "OGB-C"; else if(datum == "OGB_D") datum = "OGB-D"; else if(datum == "OGB_M") datum = "OGB-M"; else if(datum == "OGB_7") datum = "OGB-7"; kwl.add(ossimKeywordNames::DATUM_KW, datum, true); } } } } } if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimGdalProjectionFactory: createProjection KWL = \n " << kwl << std::endl; } GDALClose(h); proj = ossimProjectionFactoryRegistry::instance()->createProjection(kwl); } return proj; }