38 #pragma GCC diagnostic push
39 #pragma GCC diagnostic ignored "-Wpedantic"
41 #include <ogrsf_frmts.h>
43 #pragma GCC diagnostic pop
54 if (!oc.
isSet(
"shapefile-prefixes")) {
58 std::vector<std::string> files = oc.
getStringVector(
"shapefile-prefixes");
59 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
61 load(*file, oc, toFill, tm);
74 const std::string idField = oc.
getString(
"shapefile.id-column");
75 const bool useRunningID = oc.
getBool(
"shapefile.use-running-id") || idField ==
"";
77 std::string shpName = file +
".shp";
79 if (oc.
getString(
"shapefile.fill") ==
"true") {
81 }
else if (oc.
getString(
"shapefile.fill") ==
"false") {
84 #if GDAL_VERSION_MAJOR < 2
86 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(shpName.c_str(), FALSE);
89 GDALDataset* poDS = (GDALDataset*) GDALOpenEx(shpName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
92 throw ProcessError(
"Could not open shape description '" + shpName +
"'.");
96 OGRLayer* poLayer = poDS->GetLayer(0);
97 poLayer->ResetReading();
100 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
101 OGRSpatialReference destTransf;
103 destTransf.SetWellKnownGeogCS(
"WGS84");
104 #if GDAL_VERSION_MAJOR > 2
105 if (oc.
getBool(
"shapefile.traditional-axis-mapping")) {
106 destTransf.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
109 OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf);
110 if (poCT ==
nullptr) {
111 if (oc.
getBool(
"shapefile.guess-projection")) {
112 OGRSpatialReference origTransf2;
113 origTransf2.SetWellKnownGeogCS(
"WGS84");
114 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
116 if (poCT ==
nullptr) {
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()) !=
nullptr) {
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 for (
const std::string& typeField : oc.
getStringVector(
"shapefile.type-columns")) {
139 type += poFeature->GetFieldAsString(typeField.c_str());
142 double layer = oc.
getFloat(
"layer");
145 if (type !=
"" && tm.
has(type)) {
158 if (poFeature->GetFieldIndex(
"angle") >= 0) {
159 angle = poFeature->GetFieldAsDouble(
"angle");
162 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
163 if (poGeometry == 0) {
164 OGRFeature::DestroyFeature(poFeature);
168 if (poCT !=
nullptr) {
169 poGeometry->transform(poCT);
171 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
174 OGRPoint* cgeom = (OGRPoint*) poGeometry;
175 Position pos(cgeom->getX(), cgeom->getY());
177 WRITE_ERROR(
"Unable to project coordinates for POI '" +
id +
"'.");
179 PointOfInterest* poi =
new PointOfInterest(
id, type, color, pos,
false,
"", 0, 0, layer, angle, imgFile);
180 if (toFill.
add(poi)) {
181 parCont.push_back(poi);
185 case wkbLineString: {
186 OGRLineString* cgeom = (OGRLineString*) poGeometry;
188 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
189 Position pos(cgeom->getX(j), cgeom->getY(j));
191 WRITE_ERROR(
"Unable to project coordinates for polygon '" +
id +
"'.");
195 SUMOPolygon* poly =
new SUMOPolygon(
id, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
196 if (toFill.
add(poly)) {
197 parCont.push_back(poly);
202 const bool fill = fillType < 0 || fillType == 1;
203 OGRLinearRing* cgeom = ((OGRPolygon*) poGeometry)->getExteriorRing();
205 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
206 Position pos((
double) cgeom->getX(j), (
double) cgeom->getY(j));
208 WRITE_ERROR(
"Unable to project coordinates for polygon '" +
id +
"'.");
213 if (toFill.
add(poly)) {
214 parCont.push_back(poly);
218 case wkbMultiPoint: {
219 OGRMultiPoint* cgeom = (OGRMultiPoint*) poGeometry;
220 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
221 OGRPoint* cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i);
222 Position pos(cgeom2->getX(), cgeom2->getY());
223 std::string tid =
id +
"#" +
toString(i);
225 WRITE_ERROR(
"Unable to project coordinates for POI '" + tid +
"'.");
227 PointOfInterest* poi =
new PointOfInterest(tid, type, color, pos,
false,
"", 0, 0, layer, angle, imgFile);
228 if (toFill.
add(poi)) {
229 parCont.push_back(poi);
234 case wkbMultiLineString: {
235 OGRMultiLineString* cgeom = (OGRMultiLineString*) poGeometry;
236 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
237 OGRLineString* cgeom2 = (OGRLineString*) cgeom->getGeometryRef(i);
239 std::string tid =
id +
"#" +
toString(i);
240 for (
int j = 0; j < cgeom2->getNumPoints(); j++) {
241 Position pos(cgeom2->getX(j), cgeom2->getY(j));
243 WRITE_ERROR(
"Unable to project coordinates for polygon '" + tid +
"'.");
247 SUMOPolygon* poly =
new SUMOPolygon(tid, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
248 if (toFill.
add(poly)) {
249 parCont.push_back(poly);
254 case wkbMultiPolygon: {
255 const bool fill = fillType < 0 || fillType == 1;
256 OGRMultiPolygon* cgeom = (OGRMultiPolygon*) poGeometry;
257 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
258 OGRLinearRing* cgeom2 = ((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing();
260 std::string tid =
id +
"#" +
toString(i);
261 for (
int j = 0; j < cgeom2->getNumPoints(); j++) {
262 Position pos(cgeom2->getX(j), cgeom2->getY(j));
264 WRITE_ERROR(
"Unable to project coordinates for polygon '" + tid +
"'.");
269 if (toFill.
add(poly)) {
270 parCont.push_back(poly);
276 WRITE_WARNING(
"Unsupported shape type occurred (id='" +
id +
"').");
279 if (oc.
getBool(
"shapefile.add-param")) {
280 for (std::vector<Parameterised*>::const_iterator it = parCont.begin(); it != parCont.end(); ++it) {
281 OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
282 for (
int iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
283 OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
284 if (poFieldDefn->GetNameRef() != idField) {
285 if (poFieldDefn->GetType() == OFTReal) {
286 (*it)->setParameter(poFieldDefn->GetNameRef(),
toString(poFeature->GetFieldAsDouble(iField)));
294 OGRFeature::DestroyFeature(poFeature);
296 #if GDAL_VERSION_MAJOR < 2
297 OGRDataSource::DestroyDataSource(poDS);
307 WRITE_ERROR(
"SUMO was compiled without GDAL support.");
#define WRITE_WARNING(msg)
#define PROGRESS_DONE_MESSAGE()
#define PROGRESS_BEGIN_MESSAGE(msg)
#define UNUSED_PARAMETER(x)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static methods for processing the coordinates conversion for the current net
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.
A storage for options typed value containers)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static void load(const std::string &file, OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Parses pois/polys stored within the given file.
static void loadIfSet(OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Loads pois/polygons assumed to be stored as shape files-files.
A storage for loaded polygons and pois.
bool add(SUMOPolygon *poly, bool ignorePruning=false)
Adds a polygon to the storage.
A storage for type mappings.
const TypeDef & get(const std::string &id)
Returns a type definition.
bool has(const std::string &id)
Returns the information whether the named type is known.
A point in 2D or 3D with translation and scaling methods.
void push_back_noDoublePos(const Position &p)
insert in back a non double position
static RGBColor parseColor(std::string coldef)
Parses a color information.
static const std::string DEFAULT_IMG_FILE
static const double DEFAULT_ANGLE
static std::string latin1_to_utf8(std::string str)
Transfers from Latin 1 (ISO-8859-1) to UTF-8.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
A single definition of values that shall be used for a given type.
bool discard
Information whether polygons of this type shall be discarded.
double layer
The layer to use.
double angle
The angle to use.
std::string imgFile
The image file to use.
std::string id
The new type id to use.
RGBColor color
The color to use.