46 #pragma GCC diagnostic push 47 #pragma GCC diagnostic ignored "-Wpedantic" 49 #include <ogrsf_frmts.h> 51 #pragma GCC diagnostic pop 62 if (!oc.
isSet(
"shapefile-prefixes")) {
66 std::vector<std::string> files = oc.
getStringVector(
"shapefile-prefixes");
67 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
69 load(*file, oc, toFill, tm);
82 std::string prefix = oc.
getString(
"prefix");
86 std::string idField = oc.
getString(
"shapefile.id-column");
87 bool useRunningID = oc.
getBool(
"shapefile.use-running-id");
89 std::string shpName = file +
".shp";
91 if (oc.
getString(
"shapefile.fill") ==
"true") {
93 }
else if (oc.
getString(
"shapefile.fill") ==
"false") {
96 #if GDAL_VERSION_MAJOR < 2 98 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(shpName.c_str(), FALSE);
101 GDALDataset* poDS = (GDALDataset*) GDALOpenEx(shpName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
104 throw ProcessError(
"Could not open shape description '" + shpName +
"'.");
108 OGRLayer* poLayer = poDS->GetLayer(0);
109 poLayer->ResetReading();
112 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
113 OGRSpatialReference destTransf;
115 destTransf.SetWellKnownGeogCS(
"WGS84");
116 OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf);
118 if (oc.
isSet(
"shapefile.guess-projection")) {
119 OGRSpatialReference origTransf2;
120 origTransf2.SetWellKnownGeogCS(
"WGS84");
121 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
124 WRITE_WARNING(
"Could not create geocoordinates converter; check whether proj.4 is installed.");
128 OGRFeature* poFeature;
129 poLayer->ResetReading();
131 while ((poFeature = poLayer->GetNextFeature()) != NULL) {
132 std::vector<Parameterised*> parCont;
134 std::string
id = useRunningID ?
toString(runningID) : poFeature->GetFieldAsString(idField.c_str());
138 throw ProcessError(
"Missing id under '" + idField +
"'");
142 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
143 if (poGeometry == 0) {
144 OGRFeature::DestroyFeature(poFeature);
148 poGeometry->transform(poCT);
149 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
152 OGRPoint* cgeom = (OGRPoint*) poGeometry;
153 Position pos((
double) cgeom->getX(), (double) cgeom->getY());
155 WRITE_ERROR(
"Unable to project coordinates for POI '" +
id +
"'.");
158 if (toFill.
add(poi)) {
159 parCont.push_back(poi);
163 case wkbLineString: {
164 bool fill = fillType < 0 ? false : (fillType == 1);
165 OGRLineString* cgeom = (OGRLineString*) poGeometry;
167 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
168 Position pos((
double) cgeom->getX(j), (double) cgeom->getY(j));
170 WRITE_ERROR(
"Unable to project coordinates for polygon '" +
id +
"'.");
175 if (toFill.
add(poly)) {
176 parCont.push_back(poly);
181 bool fill = fillType < 0 ? true : (fillType == 1);
182 OGRLinearRing* cgeom = ((OGRPolygon*) poGeometry)->getExteriorRing();
184 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
185 Position pos((
double) cgeom->getX(j), (double) cgeom->getY(j));
187 WRITE_ERROR(
"Unable to project coordinates for polygon '" +
id +
"'.");
192 if (toFill.
add(poly)) {
193 parCont.push_back(poly);
197 case wkbMultiPoint: {
198 OGRMultiPoint* cgeom = (OGRMultiPoint*) poGeometry;
199 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
200 OGRPoint* cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i);
201 Position pos((
double) cgeom2->getX(), (double) cgeom2->getY());
202 std::string tid =
id +
"#" +
toString(i);
204 WRITE_ERROR(
"Unable to project coordinates for POI '" + tid +
"'.");
207 if (toFill.
add(poi)) {
208 parCont.push_back(poi);
213 case wkbMultiLineString: {
214 bool fill = fillType < 0 ? false : (fillType == 1);
215 OGRMultiLineString* cgeom = (OGRMultiLineString*) poGeometry;
216 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
217 OGRLineString* cgeom2 = (OGRLineString*) cgeom->getGeometryRef(i);
219 std::string tid =
id +
"#" +
toString(i);
220 for (
int j = 0; j < cgeom2->getNumPoints(); j++) {
221 Position pos((
double) cgeom2->getX(j), (double) cgeom2->getY(j));
223 WRITE_ERROR(
"Unable to project coordinates for polygon '" + tid +
"'.");
228 if (toFill.
add(poly)) {
229 parCont.push_back(poly);
234 case wkbMultiPolygon: {
235 bool fill = fillType < 0 ? true : (fillType == 1);
236 OGRMultiPolygon* cgeom = (OGRMultiPolygon*) poGeometry;
237 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
238 OGRLinearRing* cgeom2 = ((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing();
240 std::string tid =
id +
"#" +
toString(i);
241 for (
int j = 0; j < cgeom2->getNumPoints(); j++) {
242 Position pos((
double) cgeom2->getX(j), (double) cgeom2->getY(j));
244 WRITE_ERROR(
"Unable to project coordinates for polygon '" + tid +
"'.");
249 if (toFill.
add(poly)) {
250 parCont.push_back(poly);
256 WRITE_WARNING(
"Unsupported shape type occured (id='" +
id +
"').");
259 if (oc.
getBool(
"shapefile.add-param")) {
260 for (std::vector<Parameterised*>::const_iterator it = parCont.begin(); it != parCont.end(); ++it) {
261 OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
262 for (
int iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
263 OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
264 if (poFieldDefn->GetNameRef() != idField) {
265 if (poFieldDefn->GetType() == OFTReal) {
266 (*it)->addParameter(poFieldDefn->GetNameRef(),
toString(poFeature->GetFieldAsDouble(iField)));
274 OGRFeature::DestroyFeature(poFeature);
276 #if GDAL_VERSION_MAJOR < 2 277 OGRDataSource::DestroyDataSource(poDS);
283 WRITE_ERROR(
"SUMO was compiled without GDAL support.");
static RGBColor parseColor(std::string coldef)
Parses a color information.
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
bool x2cartesian(Position &from, bool includeInBoundary=true)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
#define WRITE_WARNING(msg)
A storage for loaded polygons and pois.
static std::string latin1_to_utf8(std::string str)
Transfers from Latin 1 (ISO-8859-1) to UTF-8.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
A storage for type mappings.
static methods for processing the coordinates conversion for the current net
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A point in 2D or 3D with translation and scaling methods.
static void loadIfSet(OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Loads pois/polygons assumed to be stored as shape files-files.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static void load(const std::string &file, OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Parses pois/polys stored within the given file.
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
#define PROGRESS_BEGIN_MESSAGE(msg)
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool add(SUMO::Polygon *poly, bool ignorePruning=false)
Adds a polygon to the storage.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
A storage for options typed value containers)
void push_back_noDoublePos(const Position &p)
insert in back a non double position
#define PROGRESS_DONE_MESSAGE()