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") || origTransf !=
nullptr) {
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());
196 double layer = oc.
getFloat(
"layer");
215 if (poFeature->GetFieldIndex(
"angle") >= 0) {
216 angle = poFeature->GetFieldAsDouble(
"angle");
219 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
220 if (poGeometry == 0) {
221 OGRFeature::DestroyFeature(poFeature);
225 if (poCT !=
nullptr) {
226 poGeometry->transform(poCT);
228 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
232 OGRPoint* cgeom = (OGRPoint*) poGeometry;
233 Position pos(cgeom->getX(), cgeom->getY());
235 WRITE_ERRORF(
TL(
"Unable to project coordinates for POI '%'."),
id);
237 PointOfInterest* poi =
new PointOfInterest(
id, type, color, pos,
false,
"", 0,
false, 0, icon, layer, angle, imgFile);
238 if (toFill.
add(poi)) {
239 parCont.push_back(poi);
244 case wkbLineString25D: {
245 const PositionVector shape = toShape((OGRLineString*) poGeometry,
id);
246 SUMOPolygon* poly =
new SUMOPolygon(
id, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
247 if (toFill.
add(poly)) {
248 parCont.push_back(poly);
253 case wkbPolygon25D: {
254 const bool fill = fillType < 0 || fillType == 1;
255 const PositionVector shape = toShape(((OGRPolygon*) poGeometry)->getExteriorRing(),
id);
257 if (toFill.
add(poly)) {
258 parCont.push_back(poly);
263 case wkbMultiPoint25D: {
264 OGRMultiPoint* cgeom = (OGRMultiPoint*) poGeometry;
265 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
266 OGRPoint* cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i);
267 Position pos(cgeom2->getX(), cgeom2->getY());
268 const std::string tid =
id +
"#" +
toString(i);
270 WRITE_ERRORF(
TL(
"Unable to project coordinates for POI '%'."), tid);
272 PointOfInterest* poi =
new PointOfInterest(tid, type, color, pos,
false,
"", 0,
false, 0, icon, layer, angle, imgFile);
273 if (toFill.
add(poi)) {
274 parCont.push_back(poi);
279 case wkbMultiLineString:
280 case wkbMultiLineString25D: {
281 OGRMultiLineString* cgeom = (OGRMultiLineString*) poGeometry;
282 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
283 const std::string tid =
id +
"#" +
toString(i);
284 const PositionVector shape = toShape((OGRLineString*) cgeom->getGeometryRef(i), tid);
285 SUMOPolygon* poly =
new SUMOPolygon(tid, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
286 if (toFill.
add(poly)) {
287 parCont.push_back(poly);
292 case wkbMultiPolygon:
293 case wkbMultiPolygon25D: {
294 const bool fill = fillType < 0 || fillType == 1;
295 OGRMultiPolygon* cgeom = (OGRMultiPolygon*) poGeometry;
296 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
297 const std::string tid =
id +
"#" +
toString(i);
298 const PositionVector shape = toShape(((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing(), tid);
300 if (toFill.
add(poly)) {
301 parCont.push_back(poly);
310 if (oc.
getBool(
"shapefile.add-param")) {
311 for (std::vector<Parameterised*>::const_iterator it = parCont.begin(); it != parCont.end(); ++it) {
312 OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
313 for (
int iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
314 OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
315 if (poFieldDefn->GetNameRef() != idField) {
316 if (poFieldDefn->GetType() == OFTReal) {
317 (*it)->setParameter(poFieldDefn->GetNameRef(),
toString(poFeature->GetFieldAsDouble(iField)));
325 OGRFeature::DestroyFeature(poFeature);
327#if GDAL_VERSION_MAJOR < 2
328 OGRDataSource::DestroyDataSource(poDS);