third ogr patch from kunitoki! (fixes labels and implements feature_at_point)(ogr_4th_revision.patch)
This commit is contained in:
parent
f657a2dfe4
commit
4085e1cb16
4 changed files with 93 additions and 64 deletions
|
@ -56,11 +56,19 @@ ogr_datasource::ogr_datasource(parameters const& params)
|
|||
boost::optional<std::string> layer = params.get<std::string>("layer");
|
||||
if (!layer) throw datasource_exception("missing <layer> paramater");
|
||||
|
||||
layerName_ = *layer;
|
||||
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false);
|
||||
|
||||
dataset_ = OGRSFDriverRegistrar::Open ((*file).c_str(), FALSE);
|
||||
if (!dataset_) throw datasource_exception(CPLGetLastErrorMsg());
|
||||
|
||||
layer_ = dataset_->GetLayerByName (layerName_.c_str());
|
||||
if (! layer_) throw datasource_exception("cannot find <layer> in dataset");
|
||||
|
||||
OGREnvelope envelope;
|
||||
layer_->GetExtent (&envelope);
|
||||
extent_.init (envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY);
|
||||
|
||||
#if 0
|
||||
double x0 = -std::numeric_limits<float>::max(),
|
||||
y0 = -std::numeric_limits<float>::max(),
|
||||
|
@ -80,17 +88,11 @@ ogr_datasource::ogr_datasource(parameters const& params)
|
|||
}
|
||||
#endif
|
||||
|
||||
layer_ = dataset_->GetLayerByName ((*layer).c_str());
|
||||
if (! layer_) throw datasource_exception("cannot find <layer> in dataset");
|
||||
|
||||
OGREnvelope envelope;
|
||||
layer_->GetExtent (&envelope);
|
||||
extent_.init (envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY);
|
||||
|
||||
OGRFeatureDefn* def = layer_->GetLayerDefn ();
|
||||
if (def != 0)
|
||||
{
|
||||
for (int i = 0; i < def->GetFieldCount (); i++)
|
||||
int fld_count = def->GetFieldCount ();
|
||||
for (int i = 0; i < fld_count; i++)
|
||||
{
|
||||
OGRFieldDefn* fld = def->GetFieldDefn (i);
|
||||
|
||||
|
@ -100,42 +102,43 @@ ogr_datasource::ogr_datasource(parameters const& params)
|
|||
switch (type_oid)
|
||||
{
|
||||
case OFTInteger:
|
||||
// case OFTIntegerList:
|
||||
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer));
|
||||
break;
|
||||
|
||||
case OFTReal:
|
||||
//case OFTRealList:
|
||||
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double));
|
||||
break;
|
||||
|
||||
case OFTString:
|
||||
//case OFTStringList:
|
||||
case OFTWideString: // deprecated
|
||||
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String));
|
||||
break;
|
||||
|
||||
case OFTBinary:
|
||||
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Object));
|
||||
break;
|
||||
|
||||
|
||||
case OFTIntegerList:
|
||||
case OFTRealList:
|
||||
case OFTStringList:
|
||||
case OFTWideStringList: // deprecated !
|
||||
#ifdef MAPNIK_DEBUG
|
||||
clog << "unhandled type_oid=" << type_oid << endl;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case OFTDate:
|
||||
case OFTTime:
|
||||
case OFTDateTime: // unhandled !
|
||||
#ifdef MAPNIK_DEBUG
|
||||
clog << "unhandled type_oid="<<type_oid<<endl;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case OFTWideString:
|
||||
case OFTWideStringList: // deprecated !
|
||||
#ifdef MAPNIK_DEBUG
|
||||
clog << "deprecated type_oid="<<type_oid<<endl;
|
||||
clog << "unhandled type_oid=" << type_oid << endl;
|
||||
#endif
|
||||
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Object));
|
||||
break;
|
||||
|
||||
default: // unknown
|
||||
#ifdef MAPNIK_DEBUG
|
||||
clog << "unknown type_oid="<<type_oid<<endl;
|
||||
clog << "unknown type_oid=" << type_oid << endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
@ -181,11 +184,14 @@ featureset_ptr ogr_datasource::features(query const& q) const
|
|||
ring.addPoint (query_extent.maxx(), query_extent.miny());
|
||||
ring.addPoint (query_extent.maxx(), query_extent.maxy());
|
||||
ring.addPoint (query_extent.minx(), query_extent.maxy());
|
||||
ring.closeRings ();
|
||||
|
||||
OGRPolygon* boxPoly = new OGRPolygon();
|
||||
boxPoly->addRing (&ring);
|
||||
boxPoly->closeRings();
|
||||
|
||||
layer_->SetSpatialFilter (boxPoly);
|
||||
|
||||
#if 0
|
||||
std::ostringstream s;
|
||||
|
||||
|
@ -198,23 +204,32 @@ featureset_ptr ogr_datasource::features(query const& q) const
|
|||
s <<",\""<<*pos<<"\"";
|
||||
++pos;
|
||||
}
|
||||
s << " from " << table_<<" where "<<geometryColumn_<<" && setSRID('BOX3D(";
|
||||
s << std::setprecision(16);
|
||||
s << box.minx() << " " << box.miny() << ",";
|
||||
s << box.maxx() << " " << box.maxy() << ")'::box3d,"<<srid_<<")";
|
||||
s << " from " << layerName_ ;
|
||||
|
||||
OGRLayer * dataset_->ExecuteSQL(const char *pszSQLCommand,
|
||||
OGRGeometry *poSpatialFilter,
|
||||
const char *pszDialect );
|
||||
// execute existing SQL
|
||||
OGRLayer* layer = dataset_->ExecuteSQL (s.str(), poly);
|
||||
|
||||
// layer must be freed
|
||||
dataset_->ReleaseResultSet (layer);
|
||||
#endif
|
||||
|
||||
return featureset_ptr(new ogr_featureset(*dataset_, *layer_, boxPoly, multiple_geometries_));
|
||||
return featureset_ptr(new ogr_featureset(*dataset_, *layer_, desc_.get_encoding(), multiple_geometries_));
|
||||
}
|
||||
return featureset_ptr();
|
||||
}
|
||||
|
||||
featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const
|
||||
{
|
||||
if (dataset_ && layer_)
|
||||
{
|
||||
OGRPoint* point = new OGRPoint;
|
||||
point->setX (pt.x);
|
||||
point->setY (pt.y);
|
||||
|
||||
layer_->SetSpatialFilter (point);
|
||||
|
||||
return featureset_ptr(new ogr_featureset(*dataset_, *layer_, desc_.get_encoding(), multiple_geometries_));
|
||||
}
|
||||
return featureset_ptr();
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ class ogr_datasource : public mapnik::datasource
|
|||
int type_;
|
||||
OGRDataSource* dataset_;
|
||||
OGRLayer* layer_;
|
||||
std::string layerName_;
|
||||
mapnik::layer_descriptor desc_;
|
||||
bool multiple_geometries_;
|
||||
};
|
||||
|
|
|
@ -49,18 +49,18 @@ using mapnik::line_string_impl;
|
|||
using mapnik::polygon_impl;
|
||||
using mapnik::geometry2d;
|
||||
using mapnik::geometry_utils;
|
||||
using mapnik::transcoder;
|
||||
|
||||
ogr_featureset::ogr_featureset(OGRDataSource & dataset,
|
||||
OGRLayer & layer,
|
||||
OGRPolygon * extent,
|
||||
std::string const& encoding,
|
||||
bool multiple_geometries)
|
||||
: dataset_(dataset),
|
||||
layer_(layer),
|
||||
extent_(extent),
|
||||
tr_(new transcoder(encoding)),
|
||||
fidcolumn_(layer_.GetFIDColumn ()),
|
||||
multiple_geometries_(multiple_geometries)
|
||||
{
|
||||
layer_.SetSpatialFilter (extent_);
|
||||
layer_.ResetReading ();
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,8 @@ feature_ptr ogr_featureset::next()
|
|||
convert_geometry (geom, feature);
|
||||
|
||||
OGRFeatureDefn* def = layer_.GetLayerDefn();
|
||||
for (int i = 0; i < def->GetFieldCount(); i++)
|
||||
int fld_count = def->GetFieldCount();
|
||||
for (int i = 0; i < fld_count; i++)
|
||||
{
|
||||
OGRFieldDefn* fld = def->GetFieldDefn (i);
|
||||
OGRFieldType type_oid = fld->GetType ();
|
||||
|
@ -88,59 +89,65 @@ feature_ptr ogr_featureset::next()
|
|||
switch (type_oid)
|
||||
{
|
||||
case OFTInteger:
|
||||
// case OFTIntegerList: // TODO
|
||||
#ifdef MAPNIK_DEBUG
|
||||
clog << name << " " << feat->GetFieldAsInteger (i) << endl;
|
||||
#endif
|
||||
{
|
||||
boost::put(*feature,name,feat->GetFieldAsInteger (i));
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTReal:
|
||||
//case OFTRealList: // TODO
|
||||
#ifdef MAPNIK_DEBUG
|
||||
clog << name << " " << feat->GetFieldAsDouble (i) << endl;
|
||||
#endif
|
||||
{
|
||||
boost::put(*feature,name,feat->GetFieldAsDouble (i));
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTString:
|
||||
//case OFTStringList: // TODO
|
||||
#ifdef MAPNIK_DEBUG
|
||||
clog << name << " " << feat->GetFieldAsString (i) << endl;
|
||||
#endif
|
||||
boost::put(*feature,name,feat->GetFieldAsString (i));
|
||||
case OFTWideString: // deprecated !
|
||||
case OFTWideStringList: // deprecated !
|
||||
{
|
||||
UnicodeString ustr = tr_->transcode(feat->GetFieldAsString (i));
|
||||
boost::put(*feature,name,ustr);
|
||||
break;
|
||||
|
||||
case OFTBinary:
|
||||
#if 0
|
||||
boost::put(*feature,name,feat->GetFieldAsBinary (i, size));
|
||||
#endif
|
||||
break;
|
||||
|
||||
case OFTDate:
|
||||
case OFTTime:
|
||||
case OFTDateTime: // unhandled !
|
||||
}
|
||||
|
||||
case OFTIntegerList:
|
||||
case OFTRealList:
|
||||
case OFTStringList:
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
clog << "unhandled type_oid=" << type_oid << endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTWideString:
|
||||
case OFTWideStringList: // deprecated !
|
||||
case OFTBinary:
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
//boost::put(*feature,name,tr_->transcode(feat->GetFieldAsString (i)));
|
||||
clog << "deprecated type_oid=" << type_oid << endl;
|
||||
clog << "unhandled type_oid=" << type_oid << endl;
|
||||
#endif
|
||||
//boost::put(*feature,name,feat->GetFieldAsBinary (i, size));
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTDate:
|
||||
case OFTTime:
|
||||
case OFTDateTime: // unhandled !
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
clog << "unhandled type_oid=" << type_oid << endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
default: // unknown
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
clog << "unknown type_oid=" << type_oid << endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
OGRFeature::DestroyFeature (feat);
|
||||
|
||||
return feature;
|
||||
|
|
|
@ -24,16 +24,22 @@
|
|||
#ifndef OGR_FEATURESET_HPP
|
||||
#define OGR_FEATURESET_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/datasource.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
// ogr
|
||||
#include <ogrsf_frmts.h>
|
||||
|
||||
|
||||
class ogr_featureset : public mapnik::Featureset
|
||||
{
|
||||
public:
|
||||
ogr_featureset(OGRDataSource & dataset,
|
||||
OGRLayer & layer,
|
||||
OGRPolygon * extent,
|
||||
std::string const& encoding,
|
||||
bool multiple_geometries);
|
||||
virtual ~ogr_featureset();
|
||||
mapnik::feature_ptr next();
|
||||
|
@ -52,7 +58,7 @@ class ogr_featureset : public mapnik::Featureset
|
|||
void convert_collection (OGRGeometryCollection* geom, mapnik::feature_ptr feature);
|
||||
OGRDataSource & dataset_;
|
||||
OGRLayer & layer_;
|
||||
OGRPolygon * extent_;
|
||||
boost::scoped_ptr<mapnik::transcoder> tr_;
|
||||
const char* fidcolumn_;
|
||||
bool multiple_geometries_;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue