39#pragma warning(disable: 4435 5219 5220)
42#pragma GCC diagnostic push
43#pragma GCC diagnostic ignored "-Wpedantic"
45#include <ogrsf_frmts.h>
47#pragma GCC diagnostic pop
66 if (!oc.
isSet(
"shapefile-prefixes")) {
70 std::vector<std::string> files = oc.
getStringVector(
"shapefile-prefixes");
71 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
73 load(*file, oc, toFill, tm);
81PCLoaderArcView::toShape(OGRLineString* geom,
const std::string& tid) {
84 for (
int j = 0; j < geom->getNumPoints(); j++) {
85 if (fabs(geom->getX(j)) > 180 || fabs(geom->getY(j)) > 90) {
89 if (2 * outOfRange > geom->getNumPoints()) {
90 WRITE_WARNING(
TL(
"No coordinate system found and coordinates look already projected."));
93 WRITE_WARNING(
TL(
"Could not find geo coordinate system, assuming WGS84."));
99 for (
int j = 0; j < geom->getNumPoints(); j++) {
100 Position pos(geom->getX(j), geom->getY(j));
102 WRITE_ERROR(
"Unable to project coordinates for polygon '" + tid +
"'.");
116 const std::string idField = oc.
getString(
"shapefile.id-column");
117 const bool useRunningID = oc.
getBool(
"shapefile.use-running-id") || idField ==
"";
119 std::string shpName = file +
".shp";
121 if (oc.
getString(
"shapefile.fill") ==
"true") {
123 }
else if (oc.
getString(
"shapefile.fill") ==
"false") {
126#if GDAL_VERSION_MAJOR < 2
128 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(shpName.c_str(), FALSE);
131 GDALDataset* poDS = (GDALDataset*) GDALOpenEx(shpName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
134 throw ProcessError(
"Could not open shape description '" + shpName +
"'.");
138 OGRLayer* poLayer = poDS->GetLayer(0);
139 poLayer->ResetReading();
142 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
143 OGRSpatialReference destTransf;
145 destTransf.SetWellKnownGeogCS(
"WGS84");
146#if GDAL_VERSION_MAJOR > 2
147 if (oc.
getBool(
"shapefile.traditional-axis-mapping")) {
148 destTransf.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
151 OGRCoordinateTransformation* poCT = origTransf ==
nullptr ? nullptr : OGRCreateCoordinateTransformation(origTransf, &destTransf);
152 if (poCT ==
nullptr) {
153 if (oc.
getBool(
"shapefile.guess-projection")) {
154 OGRSpatialReference origTransf2;
155 origTransf2.SetWellKnownGeogCS(
"WGS84");
156 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
162 OGRFeature* poFeature;
163 poLayer->ResetReading();
165 while ((poFeature = poLayer->GetNextFeature()) !=
nullptr) {
166 if (runningID == 0) {
167 std::vector<std::string> fields;
168 for (
int i = 0; i < poFeature->GetFieldCount(); i++) {
169 fields.push_back(poFeature->GetFieldDefnRef(i)->GetNameRef());
173 std::vector<Parameterised*> parCont;
175 std::string
id = useRunningID ?
toString(runningID) : poFeature->GetFieldAsString(idField.c_str());
179 throw ProcessError(
"Missing id under '" + idField +
"'");
183 for (
const std::string& typeField : oc.
getStringVector(
"shapefile.type-columns")) {
187 type += poFeature->GetFieldAsString(typeField.c_str());
190 double layer = oc.
getFloat(
"layer");
208 if (poFeature->GetFieldIndex(
"angle") >= 0) {
209 angle = poFeature->GetFieldAsDouble(
"angle");
212 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
213 if (poGeometry == 0) {
214 OGRFeature::DestroyFeature(poFeature);
218 if (poCT !=
nullptr) {
219 poGeometry->transform(poCT);
221 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
224 OGRPoint* cgeom = (OGRPoint*) poGeometry;
225 Position pos(cgeom->getX(), cgeom->getY());
227 WRITE_ERROR(
"Unable to project coordinates for POI '" +
id +
"'.");
229 PointOfInterest* poi =
new PointOfInterest(
id, type, color, pos,
false,
"", 0,
false, 0, layer, angle, imgFile);
230 if (toFill.
add(poi)) {
231 parCont.push_back(poi);
236 case wkbLineString25D: {
237 const PositionVector shape = toShape((OGRLineString*) poGeometry,
id);
238 SUMOPolygon* poly =
new SUMOPolygon(
id, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
239 if (toFill.
add(poly)) {
240 parCont.push_back(poly);
245 const bool fill = fillType < 0 || fillType == 1;
246 const PositionVector shape = toShape(((OGRPolygon*) poGeometry)->getExteriorRing(),
id);
248 if (toFill.
add(poly)) {
249 parCont.push_back(poly);
253 case wkbMultiPoint: {
254 OGRMultiPoint* cgeom = (OGRMultiPoint*) poGeometry;
255 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
256 OGRPoint* cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i);
257 Position pos(cgeom2->getX(), cgeom2->getY());
258 const std::string tid =
id +
"#" +
toString(i);
260 WRITE_ERROR(
"Unable to project coordinates for POI '" + tid +
"'.");
262 PointOfInterest* poi =
new PointOfInterest(tid, type, color, pos,
false,
"", 0,
false, 0, layer, angle, imgFile);
263 if (toFill.
add(poi)) {
264 parCont.push_back(poi);
269 case wkbMultiLineString: {
270 OGRMultiLineString* cgeom = (OGRMultiLineString*) poGeometry;
271 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
272 const std::string tid =
id +
"#" +
toString(i);
273 const PositionVector shape = toShape((OGRLineString*) cgeom->getGeometryRef(i), tid);
274 SUMOPolygon* poly =
new SUMOPolygon(tid, type, color, shape,
false, fillType == 1, 1, layer, angle, imgFile);
275 if (toFill.
add(poly)) {
276 parCont.push_back(poly);
281 case wkbMultiPolygon: {
282 const bool fill = fillType < 0 || fillType == 1;
283 OGRMultiPolygon* cgeom = (OGRMultiPolygon*) poGeometry;
284 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
285 const std::string tid =
id +
"#" +
toString(i);
286 const PositionVector shape = toShape(((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing(), tid);
288 if (toFill.
add(poly)) {
289 parCont.push_back(poly);
295 WRITE_WARNING(
"Unsupported shape type occurred (id='" +
id +
"').");
298 if (oc.
getBool(
"shapefile.add-param")) {
299 for (std::vector<Parameterised*>::const_iterator it = parCont.begin(); it != parCont.end(); ++it) {
300 OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
301 for (
int iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
302 OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
303 if (poFieldDefn->GetNameRef() != idField) {
304 if (poFieldDefn->GetType() == OFTReal) {
305 (*it)->setParameter(poFieldDefn->GetNameRef(),
toString(poFeature->GetFieldAsDouble(iField)));
313 OGRFeature::DestroyFeature(poFeature);
315#if GDAL_VERSION_MAJOR < 2
316 OGRDataSource::DestroyDataSource(poDS);
#define WRITE_MESSAGE(msg)
#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
bool x2cartesian(Position &from, bool includeInBoundary=true)
Converts the given coordinate into a cartesian and optionally update myConvBoundary.
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
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 bool myWarnMissingProjection
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.