本文整理汇总了C++中OGRGeometry::IsEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRGeometry::IsEmpty方法的具体用法?C++ OGRGeometry::IsEmpty怎么用?C++ OGRGeometry::IsEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRGeometry
的用法示例。
在下文中一共展示了OGRGeometry::IsEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ICreateFeature
OGRErr OGRGeoJSONWriteLayer::ICreateFeature( OGRFeature* poFeature )
{
VSILFILE* fp = poDS_->GetOutputFile();
if( NULL == poFeature )
{
CPLDebug( "GeoJSON", "Feature is null" );
return OGRERR_INVALID_HANDLE;
}
json_object* poObj = OGRGeoJSONWriteFeature( poFeature, bWriteBBOX, nCoordPrecision );
CPLAssert( NULL != poObj );
if( nOutCounter_ > 0 )
{
/* Separate "Feature" entries in "FeatureCollection" object. */
VSIFPrintfL( fp, ",\n" );
}
VSIFPrintfL( fp, "%s", json_object_to_json_string( poObj ) );
json_object_put( poObj );
++nOutCounter_;
OGRGeometry* poGeometry = poFeature->GetGeometryRef();
if ( bWriteBBOX && !poGeometry->IsEmpty() )
{
OGREnvelope3D sEnvelope;
poGeometry->getEnvelope(&sEnvelope);
if( poGeometry->getCoordinateDimension() == 3 )
bBBOX3D = TRUE;
sEnvelopeLayer.Merge(sEnvelope);
}
return OGRERR_NONE;
}
示例2: OGRGeoJSONWriteFeature
json_object* OGRGeoJSONWriteFeature( OGRFeature* poFeature, int bWriteBBOX, int nCoordPrecision )
{
CPLAssert( NULL != poFeature );
json_object* poObj = json_object_new_object();
CPLAssert( NULL != poObj );
json_object_object_add( poObj, "type",
json_object_new_string("Feature") );
/* -------------------------------------------------------------------- */
/* Write FID if available */
/* -------------------------------------------------------------------- */
if ( poFeature->GetFID() != OGRNullFID )
{
json_object_object_add( poObj, "id",
json_object_new_int64(poFeature->GetFID()) );
}
/* -------------------------------------------------------------------- */
/* Write feature attributes to GeoJSON "properties" object. */
/* -------------------------------------------------------------------- */
json_object* poObjProps = NULL;
poObjProps = OGRGeoJSONWriteAttributes( poFeature );
json_object_object_add( poObj, "properties", poObjProps );
/* -------------------------------------------------------------------- */
/* Write feature geometry to GeoJSON "geometry" object. */
/* Null geometries are allowed, according to the GeoJSON Spec. */
/* -------------------------------------------------------------------- */
json_object* poObjGeom = NULL;
OGRGeometry* poGeometry = poFeature->GetGeometryRef();
if ( NULL != poGeometry )
{
poObjGeom = OGRGeoJSONWriteGeometry( poGeometry, nCoordPrecision );
if ( bWriteBBOX && !poGeometry->IsEmpty() )
{
OGREnvelope3D sEnvelope;
poGeometry->getEnvelope(&sEnvelope);
json_object* poObjBBOX = json_object_new_array();
json_object_array_add(poObjBBOX,
json_object_new_double_with_precision(sEnvelope.MinX, nCoordPrecision));
json_object_array_add(poObjBBOX,
json_object_new_double_with_precision(sEnvelope.MinY, nCoordPrecision));
if (poGeometry->getCoordinateDimension() == 3)
json_object_array_add(poObjBBOX,
json_object_new_double_with_precision(sEnvelope.MinZ, nCoordPrecision));
json_object_array_add(poObjBBOX,
json_object_new_double_with_precision(sEnvelope.MaxX, nCoordPrecision));
json_object_array_add(poObjBBOX,
json_object_new_double_with_precision(sEnvelope.MaxY, nCoordPrecision));
if (poGeometry->getCoordinateDimension() == 3)
json_object_array_add(poObjBBOX,
json_object_new_double_with_precision(sEnvelope.MaxZ, nCoordPrecision));
json_object_object_add( poObj, "bbox", poObjBBOX );
}
}
json_object_object_add( poObj, "geometry", poObjGeom );
return poObj;
}
示例3: next
feature_ptr ogr_featureset::next()
{
if (count_ == 0)
{
// Reset the layer reading on the first feature read
// this is a hack, but needed due to https://github.com/mapnik/mapnik/issues/2048
// Proper solution is to avoid storing layer state in featureset
layer_.ResetReading();
}
OGRFeature *poFeature;
while ((poFeature = layer_.GetNextFeature()) != nullptr)
{
// ogr feature ids start at 0, so add one to stay
// consistent with other mapnik datasources that start at 1
mapnik::value_integer feature_id = (poFeature->GetFID() + 1);
feature_ptr feature(feature_factory::create(ctx_,feature_id));
OGRGeometry* geom = poFeature->GetGeometryRef();
if (geom && ! geom->IsEmpty())
{
auto geom_corrected = ogr_converter::convert_geometry(geom);
mapnik::geometry::correct(geom_corrected);
feature->set_geometry(std::move(geom_corrected));
}
else
{
MAPNIK_LOG_DEBUG(ogr) << "ogr_featureset: Feature with null geometry="
<< poFeature->GetFID();
OGRFeature::DestroyFeature( poFeature );
continue;
}
++count_;
int fld_count = layerdef_->GetFieldCount();
for (int i = 0; i < fld_count; i++)
{
OGRFieldDefn* fld = layerdef_->GetFieldDefn(i);
const OGRFieldType type_oid = fld->GetType();
const std::string fld_name = fld->GetNameRef();
switch (type_oid)
{
case OFTInteger:
{
feature->put<mapnik::value_integer>( fld_name, poFeature->GetFieldAsInteger(i));
break;
}
#if GDAL_VERSION_MAJOR >= 2
case OFTInteger64:
{
feature->put<mapnik::value_integer>( fld_name, poFeature->GetFieldAsInteger64(i));
break;
}
#endif
case OFTReal:
{
feature->put( fld_name, poFeature->GetFieldAsDouble(i));
break;
}
case OFTString:
case OFTWideString: // deprecated !
{
feature->put( fld_name, tr_->transcode(poFeature->GetFieldAsString(i)));
break;
}
case OFTIntegerList:
#if GDAL_VERSION_MAJOR >= 2
case OFTInteger64List:
#endif
case OFTRealList:
case OFTStringList:
case OFTWideStringList: // deprecated !
{
MAPNIK_LOG_WARN(ogr) << "ogr_featureset: Unhandled type_oid=" << type_oid;
break;
}
case OFTBinary:
{
MAPNIK_LOG_WARN(ogr) << "ogr_featureset: Unhandled type_oid=" << type_oid;
//feature->put(name,feat->GetFieldAsBinary (i, size));
break;
}
case OFTDate:
case OFTTime:
case OFTDateTime: // unhandled !
{
MAPNIK_LOG_WARN(ogr) << "ogr_featureset: Unhandled type_oid=" << type_oid;
break;
}
default: // unknown
{
MAPNIK_LOG_WARN(ogr) << "ogr_featureset: Unknown type_oid=" << type_oid;
break;
//.........这里部分代码省略.........
示例4: next
feature_ptr ogr_featureset::next()
{
OGRFeature *poFeature;
while ((poFeature = layer_.GetNextFeature()) != NULL)
{
// ogr feature ids start at 0, so add one to stay
// consistent with other mapnik datasources that start at 1
const int feature_id = (poFeature->GetFID() + 1);
feature_ptr feature(feature_factory::create(ctx_,feature_id));
OGRGeometry* geom = poFeature->GetGeometryRef();
if (geom && ! geom->IsEmpty())
{
ogr_converter::convert_geometry(geom, feature);
}
else
{
MAPNIK_LOG_DEBUG(ogr) << "ogr_featureset: Feature with null geometry="
<< poFeature->GetFID();
OGRFeature::DestroyFeature( poFeature );
continue;
}
++count_;
int fld_count = layerdef_->GetFieldCount();
for (int i = 0; i < fld_count; i++)
{
OGRFieldDefn* fld = layerdef_->GetFieldDefn(i);
const OGRFieldType type_oid = fld->GetType();
const std::string fld_name = fld->GetNameRef();
switch (type_oid)
{
case OFTInteger:
{
feature->put( fld_name, poFeature->GetFieldAsInteger(i));
break;
}
case OFTReal:
{
feature->put( fld_name, poFeature->GetFieldAsDouble(i));
break;
}
case OFTString:
case OFTWideString: // deprecated !
{
UnicodeString ustr = tr_->transcode(poFeature->GetFieldAsString(i));
feature->put( fld_name, ustr);
break;
}
case OFTIntegerList:
case OFTRealList:
case OFTStringList:
case OFTWideStringList: // deprecated !
{
MAPNIK_LOG_WARN(ogr) << "ogr_featureset: Unhandled type_oid=" << type_oid;
break;
}
case OFTBinary:
{
MAPNIK_LOG_WARN(ogr) << "ogr_featureset: Unhandled type_oid=" << type_oid;
//feature->put(name,feat->GetFieldAsBinary (i, size));
break;
}
case OFTDate:
case OFTTime:
case OFTDateTime: // unhandled !
{
MAPNIK_LOG_WARN(ogr) << "ogr_featureset: Unhandled type_oid=" << type_oid;
break;
}
default: // unknown
{
MAPNIK_LOG_WARN(ogr) << "ogr_featureset: Unknown type_oid=" << type_oid;
break;
}
}
}
OGRFeature::DestroyFeature( poFeature );
return feature;
}
MAPNIK_LOG_DEBUG(ogr) << "ogr_featureset: " << count_ << " features";
return feature_ptr();
}
示例5: CreateFeature
OGRErr OGRBNALayer::CreateFeature( OGRFeature *poFeature )
{
int i,j,k,n;
OGRGeometry *poGeom = poFeature->GetGeometryRef();
char eol[3];
const char* partialEol = (poDS->GetMultiLine()) ? eol : poDS->GetCoordinateSeparator();
if (poGeom == NULL || poGeom->IsEmpty() )
{
CPLError(CE_Failure, CPLE_AppDefined,
"OGR BNA driver cannot write features with empty geometries.");
return OGRERR_FAILURE;
}
if (poDS->GetUseCRLF())
{
eol[0] = 13;
eol[1] = 10;
eol[2] = 0;
}
else
{
eol[0] = 10;
eol[1] = 0;
}
if ( ! bWriter )
{
return OGRERR_FAILURE;
}
if( poFeature->GetFID() == OGRNullFID )
poFeature->SetFID( nFeatures++ );
VSILFILE* fp = poDS->GetOutputFP();
int nbPairPerLine = poDS->GetNbPairPerLine();
switch( poGeom->getGeometryType() )
{
case wkbPoint:
case wkbPoint25D:
{
OGRPoint* point = (OGRPoint*)poGeom;
WriteFeatureAttributes(fp, poFeature);
VSIFPrintfL( fp, "1");
VSIFPrintfL( fp, "%s", partialEol);
WriteCoord(fp, point->getX(), point->getY());
VSIFPrintfL( fp, "%s", eol);
break;
}
case wkbPolygon:
case wkbPolygon25D:
{
OGRPolygon* polygon = (OGRPolygon*)poGeom;
OGRLinearRing* ring = polygon->getExteriorRing();
if (ring == NULL)
{
return OGRERR_FAILURE;
}
double firstX = ring->getX(0);
double firstY = ring->getY(0);
int nBNAPoints = ring->getNumPoints();
int is_ellipse = FALSE;
/* This code tries to detect an ellipse in a polygon geometry */
/* This will only work presumably on ellipses already read from a BNA file */
/* Mostly a BNA to BNA feature... */
if (poDS->GetEllipsesAsEllipses() &&
polygon->getNumInteriorRings() == 0 &&
nBNAPoints == 361)
{
double oppositeX = ring->getX(180);
double oppositeY = ring->getY(180);
double quarterX = ring->getX(90);
double quarterY = ring->getY(90);
double antiquarterX = ring->getX(270);
double antiquarterY = ring->getY(270);
double center1X = 0.5*(firstX + oppositeX);
double center1Y = 0.5*(firstY + oppositeY);
double center2X = 0.5*(quarterX + antiquarterX);
double center2Y = 0.5*(quarterY + antiquarterY);
if (fabs(center1X - center2X) < 1e-5 && fabs(center1Y - center2Y) < 1e-5 &&
fabs(oppositeY - firstY) < 1e-5 &&
fabs(quarterX - antiquarterX) < 1e-5)
{
double major_radius = fabs(firstX - center1X);
double minor_radius = fabs(quarterY - center1Y);
is_ellipse = TRUE;
for(i=0;i<360;i++)
{
if (!(fabs(center1X + major_radius * cos(i * (M_PI / 180)) - ring->getX(i)) < 1e-5 &&
fabs(center1Y + minor_radius * sin(i * (M_PI / 180)) - ring->getY(i)) < 1e-5))
{
is_ellipse = FALSE;
break;
}
}
//.........这里部分代码省略.........
示例6: GetExtent
OGRErr OGRLayer::GetExtent(OGREnvelope *psExtent, int bForce )
{
OGRFeature *poFeature;
OGREnvelope oEnv;
GBool bExtentSet = FALSE;
psExtent->MinX = 0.0;
psExtent->MaxX = 0.0;
psExtent->MinY = 0.0;
psExtent->MaxY = 0.0;
/* -------------------------------------------------------------------- */
/* If this layer has a none geometry type, then we can */
/* reasonably assume there are not extents available. */
/* -------------------------------------------------------------------- */
if( GetLayerDefn()->GetGeomType() == wkbNone )
return OGRERR_FAILURE;
/* -------------------------------------------------------------------- */
/* If not forced, we should avoid having to scan all the */
/* features and just return a failure. */
/* -------------------------------------------------------------------- */
if( !bForce )
return OGRERR_FAILURE;
/* -------------------------------------------------------------------- */
/* OK, we hate to do this, but go ahead and read through all */
/* the features to collect geometries and build extents. */
/* -------------------------------------------------------------------- */
ResetReading();
while( (poFeature = GetNextFeature()) != NULL )
{
OGRGeometry *poGeom = poFeature->GetGeometryRef();
if (poGeom == NULL || poGeom->IsEmpty())
{
/* Do nothing */
}
else if (!bExtentSet)
{
poGeom->getEnvelope(psExtent);
bExtentSet = TRUE;
}
else
{
poGeom->getEnvelope(&oEnv);
if (oEnv.MinX < psExtent->MinX)
psExtent->MinX = oEnv.MinX;
if (oEnv.MinY < psExtent->MinY)
psExtent->MinY = oEnv.MinY;
if (oEnv.MaxX > psExtent->MaxX)
psExtent->MaxX = oEnv.MaxX;
if (oEnv.MaxY > psExtent->MaxY)
psExtent->MaxY = oEnv.MaxY;
}
delete poFeature;
}
ResetReading();
return (bExtentSet ? OGRERR_NONE : OGRERR_FAILURE);
}
示例7: switch
boost::optional<mapnik::datasource_geometry_t> ogr_datasource::get_geometry_type() const
{
boost::optional<mapnik::datasource_geometry_t> result;
if (dataset_ && layer_.is_valid())
{
OGRLayer* layer = layer_.layer();
// NOTE: wkbFlatten macro in ogr flattens 2.5d types into base 2d type
#if GDAL_VERSION_NUM < 1800
switch (wkbFlatten(layer->GetLayerDefn()->GetGeomType()))
#else
switch (wkbFlatten(layer->GetGeomType()))
#endif
{
case wkbPoint:
case wkbMultiPoint:
result.reset(mapnik::datasource_geometry_t::Point);
break;
case wkbLinearRing:
case wkbLineString:
case wkbMultiLineString:
result.reset(mapnik::datasource_geometry_t::LineString);
break;
case wkbPolygon:
case wkbMultiPolygon:
result.reset(mapnik::datasource_geometry_t::Polygon);
break;
case wkbGeometryCollection:
result.reset(mapnik::datasource_geometry_t::Collection);
break;
case wkbNone:
case wkbUnknown:
{
// fallback to inspecting first actual geometry
// TODO - csv and shapefile inspect first 4 features
if (dataset_ && layer_.is_valid())
{
layer = layer_.layer();
// only new either reset of setNext
//layer->ResetReading();
layer->SetNextByIndex(0);
OGRFeature *poFeature;
while ((poFeature = layer->GetNextFeature()) != nullptr)
{
OGRGeometry* geom = poFeature->GetGeometryRef();
if (geom && ! geom->IsEmpty())
{
switch (wkbFlatten(geom->getGeometryType()))
{
case wkbPoint:
case wkbMultiPoint:
result.reset(mapnik::datasource_geometry_t::Point);
break;
case wkbLinearRing:
case wkbLineString:
case wkbMultiLineString:
result.reset(mapnik::datasource_geometry_t::LineString);
break;
case wkbPolygon:
case wkbMultiPolygon:
result.reset(mapnik::datasource_geometry_t::Polygon);
break;
case wkbGeometryCollection:
result.reset(mapnik::datasource_geometry_t::Collection);
break;
default:
break;
}
}
OGRFeature::DestroyFeature( poFeature );
break;
}
}
break;
}
default:
break;
}
}
return result;
}
示例8: ICreateFeature
OGRErr OGRGeoJSONWriteLayer::ICreateFeature( OGRFeature* poFeature )
{
VSILFILE* fp = poDS_->GetOutputFile();
OGRFeature* poFeatureToWrite;
if( poCT_ != nullptr || bRFC7946_ )
{
poFeatureToWrite = new OGRFeature(poFeatureDefn_);
poFeatureToWrite->SetFrom( poFeature );
poFeatureToWrite->SetFID( poFeature->GetFID() );
OGRGeometry* poGeometry = poFeatureToWrite->GetGeometryRef();
if( poGeometry )
{
const char* const apszOptions[] = { "WRAPDATELINE=YES", nullptr };
OGRGeometry* poNewGeom =
OGRGeometryFactory::transformWithOptions(
poGeometry, poCT_, const_cast<char**>(apszOptions),
oTransformCache_);
if( poNewGeom == nullptr )
{
delete poFeatureToWrite;
return OGRERR_FAILURE;
}
OGREnvelope sEnvelope;
poNewGeom->getEnvelope(&sEnvelope);
if( sEnvelope.MinX < -180.0 || sEnvelope.MaxX > 180.0 ||
sEnvelope.MinY < -90.0 || sEnvelope.MaxY > 90.0 )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Geometry extent outside of [-180.0,180.0]x[-90.0,90.0] bounds");
delete poFeatureToWrite;
return OGRERR_FAILURE;
}
poFeatureToWrite->SetGeometryDirectly( poNewGeom );
}
}
else
{
poFeatureToWrite = poFeature;
}
json_object* poObj =
OGRGeoJSONWriteFeature( poFeatureToWrite, oWriteOptions_ );
CPLAssert( nullptr != poObj );
if( nOutCounter_ > 0 )
{
/* Separate "Feature" entries in "FeatureCollection" object. */
VSIFPrintfL( fp, ",\n" );
}
VSIFPrintfL( fp, "%s", json_object_to_json_string( poObj ) );
json_object_put( poObj );
++nOutCounter_;
OGRGeometry* poGeometry = poFeatureToWrite->GetGeometryRef();
if( bWriteFC_BBOX && poGeometry != nullptr && !poGeometry->IsEmpty() )
{
OGREnvelope3D sEnvelope = OGRGeoJSONGetBBox( poGeometry,
oWriteOptions_ );
if( poGeometry->getCoordinateDimension() == 3 )
bBBOX3D = true;
if( !sEnvelopeLayer.IsInit() )
{
sEnvelopeLayer = sEnvelope;
}
else if( oWriteOptions_.bBBOXRFC7946 )
{
const bool bEnvelopeCrossAM = ( sEnvelope.MinX > sEnvelope.MaxX );
const bool bEnvelopeLayerCrossAM =
( sEnvelopeLayer.MinX > sEnvelopeLayer.MaxX );
if( bEnvelopeCrossAM )
{
if( bEnvelopeLayerCrossAM )
{
sEnvelopeLayer.MinX = std::min(sEnvelopeLayer.MinX,
sEnvelope.MinX);
sEnvelopeLayer.MaxX = std::max(sEnvelopeLayer.MaxX,
sEnvelope.MaxX);
}
else
{
if( sEnvelopeLayer.MinX > 0 )
{
sEnvelopeLayer.MinX = std::min(sEnvelopeLayer.MinX,
sEnvelope.MinX);
sEnvelopeLayer.MaxX = sEnvelope.MaxX;
}
else if( sEnvelopeLayer.MaxX < 0 )
{
sEnvelopeLayer.MaxX = std::max(sEnvelopeLayer.MaxX,
sEnvelope.MaxX);
sEnvelopeLayer.MinX = sEnvelope.MinX;
}
else
{
//.........这里部分代码省略.........
示例9: main
int main (int argc, const char * argv[]) {
time_t startTime = time(NULL);
if (argc < 2 || strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
usage();
return(0);
}
OGRGeometry *geometry;
for (int argNum = 1; argNum < argc; ++argNum) {
//-- whether to compute the robustness or not
if (strcmp(argv[argNum], "--robustness") == 0) {
computeRobustness = true;
}
//-- whether to use the point set topology paradigm or not
//-- if not, odd-even paradigm is used by default
else if (strcmp(argv[argNum], "--setdiff") == 0) {
pointSet = true;
}
//-- mininum area to keep in output
else if (strcmp(argv[argNum], "--minarea") == 0) {
minArea = atof(argv[argNum+1]);
++argNum;
}
//-- ISR snapping tolerance
else if (strcmp(argv[argNum], "--isr") == 0) {
isrTolerance = atof(argv[argNum+1]);
++argNum;
// TODO : scale dataset if tolerance < 1.0 because of CGAL bug
}
//-- output a shapefile (out.shp) instead of a WKT
else if (strcmp(argv[argNum], "--shpOut") == 0) {
shpOut = true;
}
//-- time the results
else if (strcmp(argv[argNum], "--time") == 0) {
timeResults = true;
}
//-- reading from WKT passed directly
else if (strcmp(argv[argNum], "--wkt") == 0) {
unsigned int bufferSize = 100000000;
char *inputWKT = (char *)malloc(bufferSize*sizeof(char));
strcpy(inputWKT, argv[argNum+1]);
++argNum;
OGRErr err = OGRGeometryFactory::createFromWkt(&inputWKT, NULL, &geometry);
if (err != OGRERR_NONE) {
switch (err) {
case OGRERR_UNSUPPORTED_GEOMETRY_TYPE:
std::cerr << "Error: geometry must be Polygon or MultiPolygon" << std::endl;
break;
case OGRERR_NOT_ENOUGH_DATA:
case OGRERR_CORRUPT_DATA:
std::cerr << "Error: corrupted input" << std::endl;
break;
default:
std::cerr << "Error: corrupted input" << std::endl;
break;
}
return 1;
}
if (geometry->IsEmpty() == 1) {
std::cerr << "Error: empty geometry" << std::endl;
return 1;
}
if ( (geometry->getGeometryType() != wkbPolygon) &&
(geometry->getGeometryType() != wkbMultiPolygon) ) {
std::cerr << "Error: geometry must be Polygon or MultiPolygon" << std::endl;
return 1;
}
}
//-- reading from WKT stored in first line of a text file
else if (strcmp(argv[argNum], "-f") == 0) {
unsigned int bufferSize = 100000000;
char *inputWKT = (char *)malloc(bufferSize*sizeof(char));
if (argNum + 1 <= argc - 1 && argv[argNum+1][0] != '-') {
std::ifstream infile(argv[argNum+1], std::ifstream::in);
infile.getline(inputWKT, bufferSize);
++argNum;
} else {
std::cerr << "Error: Missing input file name." << std::endl;
return 1;
}
OGRGeometryFactory::createFromWkt(&inputWKT, NULL, &geometry);
if (geometry == NULL) {
std::cout << "Error: WKT is not valid" << std::endl;
return 1;
}
}
//-- reading from a ogr dataset (most supported: shp, geojson, gml, etc)
else if (strcmp(argv[argNum], "--ogr") == 0) {
//.........这里部分代码省略.........
示例10: OGR2SQLITEDealWithSpatialColumn
//.........这里部分代码省略.........
wkbHasZ( poLayer->GetGeomType() ) ? "XYZ" : "XY",
nSRSId, static_cast<int>(bCreateSpatialIndex) );
}
}
#endif // HAVE_SPATIALITE
char* pszErrMsg = NULL;
int rc = sqlite3_exec( hDB, osSQL.c_str(), NULL, NULL, &pszErrMsg );
if( pszErrMsg != NULL )
{
CPLDebug("SQLITE", "%s -> %s", osSQL.c_str(), pszErrMsg);
sqlite3_free(pszErrMsg);
}
#ifdef HAVE_SPATIALITE
/* -------------------------------------------------------------------- */
/* Should we create a spatial index ?. */
/* -------------------------------------------------------------------- */
if( !bSpatialiteDB || !bCreateSpatialIndex )
return rc == SQLITE_OK;
CPLDebug("SQLITE", "Create spatial index %s", osIdxNameRaw.c_str());
/* ENABLE_VIRTUAL_OGR_SPATIAL_INDEX is not defined */
#ifdef ENABLE_VIRTUAL_OGR_SPATIAL_INDEX
osSQL.Printf("CREATE VIRTUAL TABLE \"%s\" USING "
"VirtualOGRSpatialIndex(%d, '%s', pkid, xmin, xmax, ymin, ymax)",
osIdxNameEscaped.c_str(),
nExtraDS,
OGRSQLiteEscape(oLayerDesc.osLayerName).c_str());
rc = sqlite3_exec( hDB, osSQL.c_str(), NULL, NULL, NULL );
if( rc != SQLITE_OK )
{
CPLDebug( "SQLITE",
"Error occurred during spatial index creation : %s",
sqlite3_errmsg(hDB));
}
#else // ENABLE_VIRTUAL_OGR_SPATIAL_INDEX
rc = sqlite3_exec( hDB, "BEGIN", NULL, NULL, NULL );
osSQL.Printf("CREATE VIRTUAL TABLE \"%s\" "
"USING rtree(pkid, xmin, xmax, ymin, ymax)",
osIdxNameEscaped.c_str());
if( rc == SQLITE_OK )
rc = sqlite3_exec( hDB, osSQL.c_str(), NULL, NULL, NULL );
sqlite3_stmt *hStmt = NULL;
if( rc == SQLITE_OK )
{
const char* pszInsertInto = CPLSPrintf(
"INSERT INTO \"%s\" (pkid, xmin, xmax, ymin, ymax) "
"VALUES (?,?,?,?,?)", osIdxNameEscaped.c_str());
rc = sqlite3_prepare(hDB, pszInsertInto, -1, &hStmt, NULL);
}
OGRFeature* poFeature;
OGREnvelope sEnvelope;
OGR2SQLITE_IgnoreAllFieldsExceptGeometry(poLayer);
poLayer->ResetReading();
while( rc == SQLITE_OK &&
(poFeature = poLayer->GetNextFeature()) != NULL )
{
OGRGeometry* poGeom = poFeature->GetGeometryRef();
if( poGeom != NULL && !poGeom->IsEmpty() )
{
poGeom->getEnvelope(&sEnvelope);
sqlite3_bind_int64(hStmt, 1,
(sqlite3_int64) poFeature->GetFID() );
sqlite3_bind_double(hStmt, 2, sEnvelope.MinX);
sqlite3_bind_double(hStmt, 3, sEnvelope.MaxX);
sqlite3_bind_double(hStmt, 4, sEnvelope.MinY);
sqlite3_bind_double(hStmt, 5, sEnvelope.MaxY);
rc = sqlite3_step(hStmt);
if( rc == SQLITE_OK || rc == SQLITE_DONE )
rc = sqlite3_reset(hStmt);
}
delete poFeature;
}
poLayer->SetIgnoredFields(NULL);
sqlite3_finalize(hStmt);
if( rc == SQLITE_OK )
rc = sqlite3_exec( hDB, "COMMIT", NULL, NULL, NULL );
else
{
CPLDebug( "SQLITE",
"Error occurred during spatial index creation : %s",
sqlite3_errmsg(hDB));
rc = sqlite3_exec( hDB, "ROLLBACK", NULL, NULL, NULL );
}
#endif // ENABLE_VIRTUAL_OGR_SPATIAL_INDEX
#endif // HAVE_SPATIALITE
return rc == SQLITE_OK;
}
示例11: ICreateFeature
OGRErr OGRDXFWriterLayer::ICreateFeature( OGRFeature *poFeature )
{
OGRGeometry *poGeom = poFeature->GetGeometryRef();
OGRwkbGeometryType eGType = wkbNone;
if( poGeom != nullptr )
{
if( !poGeom->IsEmpty() )
{
OGREnvelope sEnvelope;
poGeom->getEnvelope(&sEnvelope);
poDS->UpdateExtent(&sEnvelope);
}
eGType = wkbFlatten(poGeom->getGeometryType());
}
if( eGType == wkbPoint )
{
const char *pszBlockName = poFeature->GetFieldAsString("BlockName");
// We don't want to treat as a blocks ref if the block is not defined
if( pszBlockName
&& poDS->oHeaderDS.LookupBlock(pszBlockName) == nullptr )
{
if( poDS->poBlocksLayer == nullptr
|| poDS->poBlocksLayer->FindBlock(pszBlockName) == nullptr )
pszBlockName = nullptr;
}
if( pszBlockName != nullptr )
return WriteINSERT( poFeature );
else if( poFeature->GetStyleString() != nullptr
&& STARTS_WITH_CI(poFeature->GetStyleString(), "LABEL") )
return WriteTEXT( poFeature );
else
return WritePOINT( poFeature );
}
else if( eGType == wkbLineString
|| eGType == wkbMultiLineString )
return WritePOLYLINE( poFeature );
else if( eGType == wkbPolygon
|| eGType == wkbTriangle
|| eGType == wkbMultiPolygon)
{
if( bWriteHatch )
return WriteHATCH( poFeature );
else
return WritePOLYLINE( poFeature );
}
// Explode geometry collections into multiple entities.
else if( eGType == wkbGeometryCollection )
{
OGRGeometryCollection *poGC =
poFeature->StealGeometry()->toGeometryCollection();
for( auto&& poMember: poGC )
{
poFeature->SetGeometry( poMember );
OGRErr eErr = CreateFeature( poFeature );
if( eErr != OGRERR_NONE )
{
delete poGC;
return eErr;
}
}
poFeature->SetGeometryDirectly( poGC );
return OGRERR_NONE;
}
else
{
CPLError( CE_Failure, CPLE_AppDefined,
"No known way to write feature with geometry '%s'.",
OGRGeometryTypeToName(eGType) );
return OGRERR_FAILURE;
}
}
示例12: CreateFeature
OGRErr OGRGMLLayer::CreateFeature( OGRFeature *poFeature )
{
int bIsGML3Output = poDS->IsGML3Output();
VSILFILE *fp = poDS->GetOutputFP();
int bWriteSpaceIndentation = poDS->WriteSpaceIndentation();
if( !bWriter )
return OGRERR_FAILURE;
if (bWriteSpaceIndentation)
VSIFPrintfL(fp, " ");
if (bIsGML3Output)
poDS->PrintLine( fp, "<ogr:featureMember>" );
else
poDS->PrintLine( fp, "<gml:featureMember>" );
if( poFeature->GetFID() == OGRNullFID )
poFeature->SetFID( iNextGMLId++ );
int nGMLIdIndex = -1;
if (bWriteSpaceIndentation)
VSIFPrintfL(fp, " ");
if (bIsGML3Output)
{
nGMLIdIndex = poFeatureDefn->GetFieldIndex("gml_id");
if (nGMLIdIndex >= 0 && poFeature->IsFieldSet( nGMLIdIndex ) )
poDS->PrintLine( fp, "<ogr:%s gml:id=\"%s\">",
poFeatureDefn->GetName(),
poFeature->GetFieldAsString(nGMLIdIndex) );
else
poDS->PrintLine( fp, "<ogr:%s gml:id=\"%s.%ld\">",
poFeatureDefn->GetName(),
poFeatureDefn->GetName(),
poFeature->GetFID() );
}
else
poDS->PrintLine( fp, "<ogr:%s fid=\"F%ld\">",
poFeatureDefn->GetName(),
poFeature->GetFID() );
// Write out Geometry - for now it isn't indented properly.
/* GML geometries don't like very much the concept of empty geometry */
OGRGeometry* poGeom = poFeature->GetGeometryRef();
if( poGeom != NULL && !poGeom->IsEmpty())
{
char *pszGeometry;
OGREnvelope sGeomBounds;
poGeom->getEnvelope( &sGeomBounds );
poDS->GrowExtents( &sGeomBounds );
if (bIsGML3Output)
{
int bCoordSwap;
if (poGeom->getSpatialReference() == NULL && poSRS != NULL)
poGeom->assignSpatialReference(poSRS);
char* pszSRSName = GML_GetSRSName(poGeom->getSpatialReference(), poDS->IsLongSRSRequired(), &bCoordSwap);
char szLowerCorner[75], szUpperCorner[75];
if (bCoordSwap)
{
OGRMakeWktCoordinate(szLowerCorner, sGeomBounds.MinY, sGeomBounds.MinX, 0, 2);
OGRMakeWktCoordinate(szUpperCorner, sGeomBounds.MaxY, sGeomBounds.MaxX, 0, 2);
}
else
{
OGRMakeWktCoordinate(szLowerCorner, sGeomBounds.MinX, sGeomBounds.MinY, 0, 2);
OGRMakeWktCoordinate(szUpperCorner, sGeomBounds.MaxX, sGeomBounds.MaxY, 0, 2);
}
if (bWriteSpaceIndentation)
VSIFPrintfL(fp, " ");
poDS->PrintLine( fp, "<gml:boundedBy><gml:Envelope%s><gml:lowerCorner>%s</gml:lowerCorner><gml:upperCorner>%s</gml:upperCorner></gml:Envelope></gml:boundedBy>",
pszSRSName, szLowerCorner, szUpperCorner);
CPLFree(pszSRSName);
}
char** papszOptions = (bIsGML3Output) ? CSLAddString(NULL, "FORMAT=GML3") : NULL;
if (bIsGML3Output && !poDS->IsLongSRSRequired())
papszOptions = CSLAddString(papszOptions, "GML3_LONGSRS=NO");
pszGeometry = poGeom->exportToGML(papszOptions);
CSLDestroy(papszOptions);
if (bWriteSpaceIndentation)
VSIFPrintfL(fp, " ");
poDS->PrintLine( fp, "<ogr:geometryProperty>%s</ogr:geometryProperty>",
pszGeometry );
CPLFree( pszGeometry );
}
// Write all "set" fields.
for( int iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
{
OGRFieldDefn *poFieldDefn = poFeatureDefn->GetFieldDefn( iField );
if( poFeature->IsFieldSet( iField ) && iField != nGMLIdIndex )
{
const char *pszRaw = poFeature->GetFieldAsString( iField );
//.........这里部分代码省略.........
示例13: ICreateFeature
//.........这里部分代码省略.........
}
else
{
nGMLIdIndex = poFeatureDefn->GetFieldIndex("fid");
if (bUseOldFIDFormat)
{
poDS->PrintLine( fp, "%s fid=\"F" CPL_FRMT_GIB "\">",
poFeatureDefn->GetName(),
poFeature->GetFID() );
}
else if (nGMLIdIndex >= 0 && poFeature->IsFieldSet( nGMLIdIndex ) )
{
poDS->PrintLine( fp, "%s fid=\"%s\">",
poFeatureDefn->GetName(),
poFeature->GetFieldAsString(nGMLIdIndex) );
}
else
{
poDS->PrintLine( fp, "%s fid=\"%s." CPL_FRMT_GIB "\">",
poFeatureDefn->GetName(),
poFeatureDefn->GetName(),
poFeature->GetFID() );
}
}
for( int iGeomField = 0; iGeomField < poFeatureDefn->GetGeomFieldCount(); iGeomField++ )
{
OGRGeomFieldDefn *poFieldDefn = poFeatureDefn->GetGeomFieldDefn(iGeomField);
// Write out Geometry - for now it isn't indented properly.
/* GML geometries don't like very much the concept of empty geometry */
OGRGeometry* poGeom = poFeature->GetGeomFieldRef(iGeomField);
if( poGeom != NULL && !poGeom->IsEmpty())
{
char *pszGeometry;
OGREnvelope3D sGeomBounds;
int nCoordDimension = poGeom->getCoordinateDimension();
poGeom->getEnvelope( &sGeomBounds );
if( bSameSRS )
poDS->GrowExtents( &sGeomBounds, nCoordDimension );
if (poGeom->getSpatialReference() == NULL && poFieldDefn->GetSpatialRef() != NULL)
poGeom->assignSpatialReference(poFieldDefn->GetSpatialRef());
if (bIsGML3Output && poDS->WriteFeatureBoundedBy())
{
bool bCoordSwap;
char* pszSRSName = GML_GetSRSName(poGeom->getSpatialReference(), poDS->IsLongSRSRequired(), &bCoordSwap);
char szLowerCorner[75], szUpperCorner[75];
if (bCoordSwap)
{
OGRMakeWktCoordinate(szLowerCorner, sGeomBounds.MinY, sGeomBounds.MinX, sGeomBounds.MinZ, nCoordDimension);
OGRMakeWktCoordinate(szUpperCorner, sGeomBounds.MaxY, sGeomBounds.MaxX, sGeomBounds.MaxZ, nCoordDimension);
}
else
{
OGRMakeWktCoordinate(szLowerCorner, sGeomBounds.MinX, sGeomBounds.MinY, sGeomBounds.MinZ, nCoordDimension);
OGRMakeWktCoordinate(szUpperCorner, sGeomBounds.MaxX, sGeomBounds.MaxY, sGeomBounds.MaxZ, nCoordDimension);
}
if (bWriteSpaceIndentation)
VSIFPrintfL(fp, " ");
poDS->PrintLine( fp, "<gml:boundedBy><gml:Envelope%s%s><gml:lowerCorner>%s</gml:lowerCorner><gml:upperCorner>%s</gml:upperCorner></gml:Envelope></gml:boundedBy>",
示例14: ICreateFeature
OGRErr OGRDXFWriterLayer::ICreateFeature( OGRFeature *poFeature )
{
OGRGeometry *poGeom = poFeature->GetGeometryRef();
OGRwkbGeometryType eGType = wkbNone;
if( poGeom != NULL )
{
if( !poGeom->IsEmpty() )
{
OGREnvelope sEnvelope;
poGeom->getEnvelope(&sEnvelope);
poDS->UpdateExtent(&sEnvelope);
}
eGType = wkbFlatten(poGeom->getGeometryType());
}
if( eGType == wkbPoint )
{
const char *pszBlockName = poFeature->GetFieldAsString("BlockName");
// we don't want to treat as a block ref if we are writing blocks layer
if( pszBlockName != NULL
&& poDS->poBlocksLayer != NULL
&& poFeature->GetDefnRef() == poDS->poBlocksLayer->GetLayerDefn())
pszBlockName = NULL;
// We don't want to treat as a blocks ref if the block is not defined
if( pszBlockName
&& poDS->oHeaderDS.LookupBlock(pszBlockName) == NULL )
{
if( poDS->poBlocksLayer == NULL
|| poDS->poBlocksLayer->FindBlock(pszBlockName) == NULL )
pszBlockName = NULL;
}
if( pszBlockName != NULL )
return WriteINSERT( poFeature );
else if( poFeature->GetStyleString() != NULL
&& EQUALN(poFeature->GetStyleString(),"LABEL",5) )
return WriteTEXT( poFeature );
else
return WritePOINT( poFeature );
}
else if( eGType == wkbLineString
|| eGType == wkbMultiLineString )
return WritePOLYLINE( poFeature );
else if( eGType == wkbPolygon
|| eGType == wkbMultiPolygon )
{
if( bWriteHatch )
return WriteHATCH( poFeature );
else
return WritePOLYLINE( poFeature );
}
// Explode geometry collections into multiple entities.
else if( eGType == wkbGeometryCollection )
{
OGRGeometryCollection *poGC = (OGRGeometryCollection *)
poFeature->StealGeometry();
int iGeom;
for( iGeom = 0; iGeom < poGC->getNumGeometries(); iGeom++ )
{
poFeature->SetGeometry( poGC->getGeometryRef(iGeom) );
OGRErr eErr = CreateFeature( poFeature );
if( eErr != OGRERR_NONE )
return eErr;
}
poFeature->SetGeometryDirectly( poGC );
return OGRERR_NONE;
}
else
{
CPLError( CE_Failure, CPLE_AppDefined,
"No known way to write feature with geometry '%s'.",
OGRGeometryTypeToName(eGType) );
return OGRERR_FAILURE;
}
}
示例15: oMutexHolder
//.........这里部分代码省略.........
{
CPLDebug("SQLITE",
"Error occured during spatial index creation : %s",
sqlite3_errmsg(hDB));
}
#else // ENABLE_VIRTUAL_OGR_SPATIAL_INDEX
rc = sqlite3_exec( hDB, "BEGIN", NULL, NULL, NULL );
osSQL.Printf("CREATE VIRTUAL TABLE \"%s\" "
"USING rtree(pkid, xmin, xmax, ymin, ymax)",
osIdxNameEscaped.c_str());
if( rc == SQLITE_OK )
rc = sqlite3_exec( hDB, osSQL.c_str(), NULL, NULL, NULL );
sqlite3_stmt *hStmt = NULL;
if( rc == SQLITE_OK )
{
const char* pszInsertInto = CPLSPrintf(
"INSERT INTO \"%s\" (pkid, xmin, xmax, ymin, ymax) "
"VALUES (?,?,?,?,?)", osIdxNameEscaped.c_str());
rc = sqlite3_prepare(hDB, pszInsertInto, -1, &hStmt, NULL);
}
OGRFeature* poFeature;
OGREnvelope sEnvelope;
OGR2SQLITE_IgnoreAllFieldsExceptGeometry(poLayer);
poLayer->ResetReading();
while( rc == SQLITE_OK &&
(poFeature = poLayer->GetNextFeature()) != NULL )
{
OGRGeometry* poGeom = poFeature->GetGeometryRef();
if( poGeom != NULL && !poGeom->IsEmpty() )
{
poGeom->getEnvelope(&sEnvelope);
sqlite3_bind_int64(hStmt, 1,
(sqlite3_int64) poFeature->GetFID() );
sqlite3_bind_double(hStmt, 2, sEnvelope.MinX);
sqlite3_bind_double(hStmt, 3, sEnvelope.MaxX);
sqlite3_bind_double(hStmt, 4, sEnvelope.MinY);
sqlite3_bind_double(hStmt, 5, sEnvelope.MaxY);
rc = sqlite3_step(hStmt);
if( rc == SQLITE_OK || rc == SQLITE_DONE )
rc = sqlite3_reset(hStmt);
}
delete poFeature;
}
poLayer->SetIgnoredFields(NULL);
sqlite3_finalize(hStmt);
if( rc == SQLITE_OK )
rc = sqlite3_exec( hDB, "COMMIT", NULL, NULL, NULL );
else
{
CPLDebug("SQLITE",
"Error occured during spatial index creation : %s",
sqlite3_errmsg(hDB));
rc = sqlite3_exec( hDB, "ROLLBACK", NULL, NULL, NULL );
}
#endif // ENABLE_VIRTUAL_OGR_SPATIAL_INDEX
#endif // HAVE_SPATIALITE