121 const std::string idField = oc.
getString(
"shapefile.id-column");
122 const bool useRunningID = oc.
getBool(
"shapefile.use-running-id") || idField ==
"";
124 std::string shpName = file +
".shp";
126 if (oc.
getString(
"shapefile.fill") ==
"true") {
128 }
else if (oc.
getString(
"shapefile.fill") ==
"false") {
131#if GDAL_VERSION_MAJOR < 2
133 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(shpName.c_str(), FALSE);
136 GDALDataset* poDS = (GDALDataset*) GDALOpenEx(shpName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
139 throw ProcessError(
TLF(
"Could not open shape description '%'.", shpName));
143 OGRLayer* poLayer = poDS->GetLayer(0);
144 poLayer->ResetReading();
147 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
148 OGRSpatialReference destTransf;
150 destTransf.SetWellKnownGeogCS(
"WGS84");
151#if GDAL_VERSION_MAJOR > 2
152 if (oc.
getBool(
"shapefile.traditional-axis-mapping")) {
153 destTransf.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
156 OGRCoordinateTransformation* poCT = origTransf ==
nullptr ? nullptr : OGRCreateCoordinateTransformation(origTransf, &destTransf);
157 if (poCT ==
nullptr) {
158 if (oc.
getBool(
"shapefile.guess-projection")) {
159 OGRSpatialReference origTransf2;
160 origTransf2.SetWellKnownGeogCS(
"WGS84");
161 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
167 OGRFeature* poFeature;
168 poLayer->ResetReading();
170 while ((poFeature = poLayer->GetNextFeature()) !=
nullptr) {
171 if (runningID == 0) {
172 std::vector<std::string> fields;
173 for (
int i = 0; i < poFeature->GetFieldCount(); i++) {
174 fields.push_back(poFeature->GetFieldDefnRef(i)->GetNameRef());
178 std::vector<Parameterised*> parCont;
180 std::string
id = useRunningID ?
toString(runningID) : poFeature->GetFieldAsString(idField.c_str());
188 for (
const std::string& typeField : oc.
getStringVector(
"shapefile.type-columns")) {
192 type += poFeature->GetFieldAsString(typeField.c_str());
195 double layer = oc.
getFloat(
"layer");
213 if (poFeature->GetFieldIndex(
"angle") >= 0) {
214 angle = poFeature->GetFieldAsDouble(
"angle");
217 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
218 if (poGeometry == 0) {
219 OGRFeature::DestroyFeature(poFeature);
223 if (poCT !=
nullptr) {
224 poGeometry->transform(poCT);
226 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
229 OGRPoint* cgeom = (OGRPoint*) poGeometry;
230 Position pos(cgeom->getX(), cgeom->getY());
232 WRITE_ERRORF(
TL(
"Unable to project coordinates for POI '%'."),
id);
234 PointOfInterest* poi =
new PointOfInterest(
id, type, color, pos,
false,
"", 0,
false, 0, layer, angle, imgFile);
235 if (toFill.
add(poi)) {
236 parCont.push_back(poi);
241 case wkbLineString25D: {
242 const PositionVector shape = toShape((OGRLineString*) poGeometry,
id);
243 SUMOPolygon* poly =
new SUMOPolygon(
id, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
244 if (toFill.
add(poly)) {
245 parCont.push_back(poly);
250 const bool fill = fillType < 0 || fillType == 1;
251 const PositionVector shape = toShape(((OGRPolygon*) poGeometry)->getExteriorRing(),
id);
253 if (toFill.
add(poly)) {
254 parCont.push_back(poly);
258 case wkbMultiPoint: {
259 OGRMultiPoint* cgeom = (OGRMultiPoint*) poGeometry;
260 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
261 OGRPoint* cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i);
262 Position pos(cgeom2->getX(), cgeom2->getY());
263 const std::string tid =
id +
"#" +
toString(i);
265 WRITE_ERRORF(
TL(
"Unable to project coordinates for POI '%'."), tid);
267 PointOfInterest* poi =
new PointOfInterest(tid, type, color, pos,
false,
"", 0,
false, 0, layer, angle, imgFile);
268 if (toFill.
add(poi)) {
269 parCont.push_back(poi);
274 case wkbMultiLineString: {
275 OGRMultiLineString* cgeom = (OGRMultiLineString*) poGeometry;
276 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
277 const std::string tid =
id +
"#" +
toString(i);
278 const PositionVector shape = toShape((OGRLineString*) cgeom->getGeometryRef(i), tid);
279 SUMOPolygon* poly =
new SUMOPolygon(tid, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
280 if (toFill.
add(poly)) {
281 parCont.push_back(poly);
286 case wkbMultiPolygon: {
287 const bool fill = fillType < 0 || fillType == 1;
288 OGRMultiPolygon* cgeom = (OGRMultiPolygon*) poGeometry;
289 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
290 const std::string tid =
id +
"#" +
toString(i);
291 const PositionVector shape = toShape(((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing(), tid);
293 if (toFill.
add(poly)) {
294 parCont.push_back(poly);
303 if (oc.
getBool(
"shapefile.add-param")) {
304 for (std::vector<Parameterised*>::const_iterator it = parCont.begin(); it != parCont.end(); ++it) {
305 OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
306 for (
int iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
307 OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
308 if (poFieldDefn->GetNameRef() != idField) {
309 if (poFieldDefn->GetType() == OFTReal) {
310 (*it)->setParameter(poFieldDefn->GetNameRef(),
toString(poFeature->GetFieldAsDouble(iField)));
318 OGRFeature::DestroyFeature(poFeature);
320#if GDAL_VERSION_MAJOR < 2
321 OGRDataSource::DestroyDataSource(poDS);