39 #pragma GCC diagnostic push 40 #pragma GCC diagnostic ignored "-Wpedantic" 42 #include <ogrsf_frmts.h> 44 #pragma GCC diagnostic pop 55 if (!oc.
isSet(
"shapefile-prefixes")) {
59 std::vector<std::string> files = oc.
getStringVector(
"shapefile-prefixes");
60 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
62 load(*file, oc, toFill, tm);
75 std::string prefix = oc.
getString(
"prefix");
79 std::string idField = oc.
getString(
"shapefile.id-column");
80 bool useRunningID = oc.
getBool(
"shapefile.use-running-id") || idField ==
"";
82 std::string shpName = file +
".shp";
84 if (oc.
getString(
"shapefile.fill") ==
"true") {
86 }
else if (oc.
getString(
"shapefile.fill") ==
"false") {
89 #if GDAL_VERSION_MAJOR < 2 91 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(shpName.c_str(), FALSE);
94 GDALDataset* poDS = (GDALDataset*) GDALOpenEx(shpName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
97 throw ProcessError(
"Could not open shape description '" + shpName +
"'.");
101 OGRLayer* poLayer = poDS->GetLayer(0);
102 poLayer->ResetReading();
105 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
106 OGRSpatialReference destTransf;
108 destTransf.SetWellKnownGeogCS(
"WGS84");
109 OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf);
111 if (oc.
isSet(
"shapefile.guess-projection")) {
112 OGRSpatialReference origTransf2;
113 origTransf2.SetWellKnownGeogCS(
"WGS84");
114 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
117 WRITE_WARNING(
"Could not create geocoordinates converter; check whether proj.4 is installed.");
121 OGRFeature* poFeature;
122 poLayer->ResetReading();
124 while ((poFeature = poLayer->GetNextFeature()) != NULL) {
125 std::vector<Parameterised*> parCont;
127 std::string
id = useRunningID ?
toString(runningID) : poFeature->GetFieldAsString(idField.c_str());
131 throw ProcessError(
"Missing id under '" + idField +
"'");
135 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
136 if (poGeometry == 0) {
137 OGRFeature::DestroyFeature(poFeature);
141 poGeometry->transform(poCT);
142 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
145 OGRPoint* cgeom = (OGRPoint*) poGeometry;
146 Position pos((
double) cgeom->getX(), (double) cgeom->getY());
148 WRITE_ERROR(
"Unable to project coordinates for POI '" +
id +
"'.");
151 if (toFill.
add(poi)) {
152 parCont.push_back(poi);
156 case wkbLineString: {
157 bool fill = fillType < 0 ? false : (fillType == 1);
158 OGRLineString* cgeom = (OGRLineString*) poGeometry;
160 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
161 Position pos((
double) cgeom->getX(j), (double) cgeom->getY(j));
163 WRITE_ERROR(
"Unable to project coordinates for polygon '" +
id +
"'.");
168 if (toFill.
add(poly)) {
169 parCont.push_back(poly);
174 bool fill = fillType < 0 ? true : (fillType == 1);
175 OGRLinearRing* cgeom = ((OGRPolygon*) poGeometry)->getExteriorRing();
177 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
178 Position pos((
double) cgeom->getX(j), (double) cgeom->getY(j));
180 WRITE_ERROR(
"Unable to project coordinates for polygon '" +
id +
"'.");
185 if (toFill.
add(poly)) {
186 parCont.push_back(poly);
190 case wkbMultiPoint: {
191 OGRMultiPoint* cgeom = (OGRMultiPoint*) poGeometry;
192 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
193 OGRPoint* cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i);
194 Position pos((
double) cgeom2->getX(), (double) cgeom2->getY());
195 std::string tid =
id +
"#" +
toString(i);
197 WRITE_ERROR(
"Unable to project coordinates for POI '" + tid +
"'.");
200 if (toFill.
add(poi)) {
201 parCont.push_back(poi);
206 case wkbMultiLineString: {
207 bool fill = fillType < 0 ? false : (fillType == 1);
208 OGRMultiLineString* cgeom = (OGRMultiLineString*) poGeometry;
209 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
210 OGRLineString* cgeom2 = (OGRLineString*) cgeom->getGeometryRef(i);
212 std::string tid =
id +
"#" +
toString(i);
213 for (
int j = 0; j < cgeom2->getNumPoints(); j++) {
214 Position pos((
double) cgeom2->getX(j), (double) cgeom2->getY(j));
216 WRITE_ERROR(
"Unable to project coordinates for polygon '" + tid +
"'.");
221 if (toFill.
add(poly)) {
222 parCont.push_back(poly);
227 case wkbMultiPolygon: {
228 bool fill = fillType < 0 ? true : (fillType == 1);
229 OGRMultiPolygon* cgeom = (OGRMultiPolygon*) poGeometry;
230 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
231 OGRLinearRing* cgeom2 = ((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing();
233 std::string tid =
id +
"#" +
toString(i);
234 for (
int j = 0; j < cgeom2->getNumPoints(); j++) {
235 Position pos((
double) cgeom2->getX(j), (double) cgeom2->getY(j));
237 WRITE_ERROR(
"Unable to project coordinates for polygon '" + tid +
"'.");
242 if (toFill.
add(poly)) {
243 parCont.push_back(poly);
249 WRITE_WARNING(
"Unsupported shape type occurred (id='" +
id +
"').");
252 if (oc.
getBool(
"shapefile.add-param")) {
253 for (std::vector<Parameterised*>::const_iterator it = parCont.begin(); it != parCont.end(); ++it) {
254 OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
255 for (
int iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
256 OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
257 if (poFieldDefn->GetNameRef() != idField) {
258 if (poFieldDefn->GetType() == OFTReal) {
259 (*it)->setParameter(poFieldDefn->GetNameRef(),
toString(poFeature->GetFieldAsDouble(iField)));
267 OGRFeature::DestroyFeature(poFeature);
269 #if GDAL_VERSION_MAJOR < 2 270 OGRDataSource::DestroyDataSource(poDS);
279 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 UNUSED_PARAMETER(x)
#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()