126 const std::string idField = oc.
getString(
"shapefile.id-column");
127 const bool useRunningID = oc.
getBool(
"shapefile.use-running-id") || idField ==
"";
129 if (oc.
getString(
"shapefile.fill") ==
"true") {
131 }
else if (oc.
getString(
"shapefile.fill") ==
"false") {
134#if GDAL_VERSION_MAJOR < 2
136 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(file.c_str(), FALSE);
139 GDALDataset* poDS = (GDALDataset*) GDALOpenEx(file.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
142 throw ProcessError(
TLF(
"Could not open shape description '%'.", file));
146 OGRLayer* poLayer = poDS->GetLayer(0);
147 poLayer->ResetReading();
150#if GDAL_VERSION_MAJOR < 3
151 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
153 const OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
155 OGRSpatialReference destTransf;
157 destTransf.SetWellKnownGeogCS(
"WGS84");
158#if GDAL_VERSION_MAJOR > 2
159 if (oc.
getBool(
"shapefile.traditional-axis-mapping") || origTransf !=
nullptr) {
160 destTransf.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
163 OGRCoordinateTransformation* poCT = origTransf ==
nullptr ? nullptr : OGRCreateCoordinateTransformation(origTransf, &destTransf);
164 if (poCT ==
nullptr) {
165 if (oc.
getBool(
"shapefile.guess-projection")) {
166 OGRSpatialReference origTransf2;
167 origTransf2.SetWellKnownGeogCS(
"WGS84");
168 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
174 OGRFeature* poFeature;
175 poLayer->ResetReading();
177 while ((poFeature = poLayer->GetNextFeature()) !=
nullptr) {
178 if (runningID == 0) {
179 std::vector<std::string> fields;
180 for (
int i = 0; i < poFeature->GetFieldCount(); i++) {
181 fields.push_back(poFeature->GetFieldDefnRef(i)->GetNameRef());
185 std::vector<Parameterised*> parCont;
187 std::string
id = useRunningID ?
toString(runningID) : poFeature->GetFieldAsString(idField.c_str());
195 for (
const std::string& typeField : oc.
getStringVector(
"shapefile.type-columns")) {
199 type += poFeature->GetFieldAsString(typeField.c_str());
203 double layer = oc.
getFloat(
"layer");
222 if (poFeature->GetFieldIndex(
"angle") >= 0) {
223 angle = poFeature->GetFieldAsDouble(
"angle");
226 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
227 if (poGeometry == 0) {
228 OGRFeature::DestroyFeature(poFeature);
232 if (poCT !=
nullptr) {
233 poGeometry->transform(poCT);
235 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
239 OGRPoint* cgeom = (OGRPoint*) poGeometry;
240 Position pos(cgeom->getX(), cgeom->getY());
242 WRITE_ERRORF(
TL(
"Unable to project coordinates for POI '%'."),
id);
244 PointOfInterest* poi =
new PointOfInterest(
id, type, color, pos,
false,
"", 0,
false, 0, icon, layer, angle, imgFile);
245 if (toFill.
add(poi)) {
246 parCont.push_back(poi);
251 case wkbLineString25D: {
252 const PositionVector shape = toShape((OGRLineString*) poGeometry,
id);
253 SUMOPolygon* poly =
new SUMOPolygon(
id, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
254 if (toFill.
add(poly)) {
255 parCont.push_back(poly);
260 case wkbPolygon25D: {
261 const bool fill = fillType < 0 || fillType == 1;
262 const PositionVector shape = toShape(((OGRPolygon*) poGeometry)->getExteriorRing(),
id);
264 if (toFill.
add(poly)) {
265 parCont.push_back(poly);
270 case wkbMultiPoint25D: {
271 OGRMultiPoint* cgeom = (OGRMultiPoint*) poGeometry;
272 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
273 OGRPoint* cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i);
274 Position pos(cgeom2->getX(), cgeom2->getY());
275 const std::string tid =
id +
"#" +
toString(i);
277 WRITE_ERRORF(
TL(
"Unable to project coordinates for POI '%'."), tid);
279 PointOfInterest* poi =
new PointOfInterest(tid, type, color, pos,
false,
"", 0,
false, 0, icon, layer, angle, imgFile);
280 if (toFill.
add(poi)) {
281 parCont.push_back(poi);
286 case wkbMultiLineString:
287 case wkbMultiLineString25D: {
288 OGRMultiLineString* cgeom = (OGRMultiLineString*) poGeometry;
289 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
290 const std::string tid =
id +
"#" +
toString(i);
291 const PositionVector shape = toShape((OGRLineString*) cgeom->getGeometryRef(i), tid);
292 SUMOPolygon* poly =
new SUMOPolygon(tid, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
293 if (toFill.
add(poly)) {
294 parCont.push_back(poly);
299 case wkbMultiPolygon:
300 case wkbMultiPolygon25D: {
301 const bool fill = fillType < 0 || fillType == 1;
302 OGRMultiPolygon* cgeom = (OGRMultiPolygon*) poGeometry;
303 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
304 const std::string tid =
id +
"#" +
toString(i);
305 const PositionVector shape = toShape(((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing(), tid);
307 if (toFill.
add(poly)) {
308 parCont.push_back(poly);
317 if (oc.
getBool(
"shapefile.add-param") || oc.
getBool(
"all-attributes")) {
318 for (std::vector<Parameterised*>::const_iterator it = parCont.begin(); it != parCont.end(); ++it) {
319 OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
320 for (
int iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
321 OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
322 if (poFieldDefn->GetNameRef() != idField) {
328 OGRFeature::DestroyFeature(poFeature);
330#if GDAL_VERSION_MAJOR < 2
331 OGRDataSource::DestroyDataSource(poDS);