45 #pragma GCC diagnostic push 46 #pragma GCC diagnostic ignored "-Wpedantic" 48 #include <ogrsf_frmts.h> 50 #pragma GCC diagnostic pop 61 if (!oc.
isSet(
"shapefile-prefixes")) {
65 std::vector<std::string> files = oc.
getStringVector(
"shapefile-prefixes");
66 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
68 load(*file, oc, toFill, tm);
81 std::string prefix = oc.
getString(
"prefix");
85 std::string idField = oc.
getString(
"shapefile.id-column");
86 bool useRunningID = oc.
getBool(
"shapefile.use-running-id") || idField ==
"";
88 std::string shpName = file +
".shp";
90 if (oc.
getString(
"shapefile.fill") ==
"true") {
92 }
else if (oc.
getString(
"shapefile.fill") ==
"false") {
95 #if GDAL_VERSION_MAJOR < 2 97 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(shpName.c_str(), FALSE);
100 GDALDataset* poDS = (GDALDataset*) GDALOpenEx(shpName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
103 throw ProcessError(
"Could not open shape description '" + shpName +
"'.");
107 OGRLayer* poLayer = poDS->GetLayer(0);
108 poLayer->ResetReading();
111 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
112 OGRSpatialReference destTransf;
114 destTransf.SetWellKnownGeogCS(
"WGS84");
115 OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf);
117 if (oc.
isSet(
"shapefile.guess-projection")) {
118 OGRSpatialReference origTransf2;
119 origTransf2.SetWellKnownGeogCS(
"WGS84");
120 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
123 WRITE_WARNING(
"Could not create geocoordinates converter; check whether proj.4 is installed.");
127 OGRFeature* poFeature;
128 poLayer->ResetReading();
130 while ((poFeature = poLayer->GetNextFeature()) != NULL) {
131 std::vector<Parameterised*> parCont;
133 std::string
id = useRunningID ?
toString(runningID) : poFeature->GetFieldAsString(idField.c_str());
137 throw ProcessError(
"Missing id under '" + idField +
"'");
141 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
142 if (poGeometry == 0) {
143 OGRFeature::DestroyFeature(poFeature);
147 poGeometry->transform(poCT);
148 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
151 OGRPoint* cgeom = (OGRPoint*) poGeometry;
152 Position pos((
double) cgeom->getX(), (double) cgeom->getY());
154 WRITE_ERROR(
"Unable to project coordinates for POI '" +
id +
"'.");
157 if (toFill.
add(poi)) {
158 parCont.push_back(poi);
162 case wkbLineString: {
163 bool fill = fillType < 0 ? false : (fillType == 1);
164 OGRLineString* cgeom = (OGRLineString*) poGeometry;
166 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
167 Position pos((
double) cgeom->getX(j), (double) cgeom->getY(j));
169 WRITE_ERROR(
"Unable to project coordinates for polygon '" +
id +
"'.");
174 if (toFill.
add(poly)) {
175 parCont.push_back(poly);
180 bool fill = fillType < 0 ? true : (fillType == 1);
181 OGRLinearRing* cgeom = ((OGRPolygon*) poGeometry)->getExteriorRing();
183 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
184 Position pos((
double) cgeom->getX(j), (double) cgeom->getY(j));
186 WRITE_ERROR(
"Unable to project coordinates for polygon '" +
id +
"'.");
191 if (toFill.
add(poly)) {
192 parCont.push_back(poly);
196 case wkbMultiPoint: {
197 OGRMultiPoint* cgeom = (OGRMultiPoint*) poGeometry;
198 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
199 OGRPoint* cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i);
200 Position pos((
double) cgeom2->getX(), (double) cgeom2->getY());
201 std::string tid =
id +
"#" +
toString(i);
203 WRITE_ERROR(
"Unable to project coordinates for POI '" + tid +
"'.");
206 if (toFill.
add(poi)) {
207 parCont.push_back(poi);
212 case wkbMultiLineString: {
213 bool fill = fillType < 0 ? false : (fillType == 1);
214 OGRMultiLineString* cgeom = (OGRMultiLineString*) poGeometry;
215 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
216 OGRLineString* cgeom2 = (OGRLineString*) cgeom->getGeometryRef(i);
218 std::string tid =
id +
"#" +
toString(i);
219 for (
int j = 0; j < cgeom2->getNumPoints(); j++) {
220 Position pos((
double) cgeom2->getX(j), (double) cgeom2->getY(j));
222 WRITE_ERROR(
"Unable to project coordinates for polygon '" + tid +
"'.");
227 if (toFill.
add(poly)) {
228 parCont.push_back(poly);
233 case wkbMultiPolygon: {
234 bool fill = fillType < 0 ? true : (fillType == 1);
235 OGRMultiPolygon* cgeom = (OGRMultiPolygon*) poGeometry;
236 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
237 OGRLinearRing* cgeom2 = ((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing();
239 std::string tid =
id +
"#" +
toString(i);
240 for (
int j = 0; j < cgeom2->getNumPoints(); j++) {
241 Position pos((
double) cgeom2->getX(j), (double) cgeom2->getY(j));
243 WRITE_ERROR(
"Unable to project coordinates for polygon '" + tid +
"'.");
248 if (toFill.
add(poly)) {
249 parCont.push_back(poly);
255 WRITE_WARNING(
"Unsupported shape type occured (id='" +
id +
"').");
258 if (oc.
getBool(
"shapefile.add-param")) {
259 for (std::vector<Parameterised*>::const_iterator it = parCont.begin(); it != parCont.end(); ++it) {
260 OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
261 for (
int iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
262 OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
263 if (poFieldDefn->GetNameRef() != idField) {
264 if (poFieldDefn->GetType() == OFTReal) {
265 (*it)->setParameter(poFieldDefn->GetNameRef(),
toString(poFeature->GetFieldAsDouble(iField)));
273 OGRFeature::DestroyFeature(poFeature);
275 #if GDAL_VERSION_MAJOR < 2 276 OGRDataSource::DestroyDataSource(poDS);
282 WRITE_ERROR(
"SUMO was compiled without GDAL support.");
static RGBColor parseColor(std::string coldef)
Parses a color information.
bool add(SUMOPolygon *poly, bool ignorePruning=false)
Adds a polygon to the storage.
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
bool x2cartesian(Position &from, bool includeInBoundary=true)
Converts the given coordinate into a cartesian and optionally update myConvBoundary.
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)
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()