Skip to content

Commit

Permalink
fixing encoding and pruning for arcview polyconvert, refactoring poly…
Browse files Browse the repository at this point in the history
… container, refs #12

git-svn-id: file:///home/behr_mi/git/sumo_synched/trunk@15611 afbd958f-9f77-42d5-a016-97a22340ccf4
  • Loading branch information
behrisch committed Feb 14, 2014
1 parent dc655e4 commit 8d9df49
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 107 deletions.
40 changes: 14 additions & 26 deletions sumo/src/polyconvert/PCLoaderArcView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ PCLoaderArcView::load(const std::string& file, OptionsCont& oc, PCPolyContainer&
// read in edge attributes
std::string id = useRunningID ? toString(runningID) : poFeature->GetFieldAsString(idField.c_str());
++runningID;
id = StringUtils::prune(id);
id = StringUtils::latin1_to_utf8(StringUtils::prune(id));
if (id == "") {
throw ProcessError("Missing id under '" + idField + "'");
}
Expand All @@ -141,11 +141,9 @@ PCLoaderArcView::load(const std::string& file, OptionsCont& oc, PCPolyContainer&
WRITE_ERROR("Unable to project coordinates for POI '" + id + "'.");
}
PointOfInterest* poi = new PointOfInterest(id, type, color, pos, (SUMOReal)layer);
if (!toFill.insert(id, poi, layer)) {
WRITE_ERROR("POI '" + id + "' could not be added.");
delete poi;
if (toFill.insert(id, poi, layer)) {
parCont.push_back(poi);
}
parCont.push_back(poi);
}
break;
case wkbLineString: {
Expand All @@ -159,11 +157,9 @@ PCLoaderArcView::load(const std::string& file, OptionsCont& oc, PCPolyContainer&
shape.push_back_noDoublePos(pos);
}
Polygon* poly = new Polygon(id, type, color, shape, false, (SUMOReal)layer);
if (!toFill.insert(id, poly, layer)) {
WRITE_ERROR("Polygon '" + id + "' could not be added.");
delete poly;
if (toFill.insert(id, poly, layer)) {
parCont.push_back(poly);
}
parCont.push_back(poly);
}
break;
case wkbPolygon: {
Expand All @@ -177,11 +173,9 @@ PCLoaderArcView::load(const std::string& file, OptionsCont& oc, PCPolyContainer&
shape.push_back_noDoublePos(pos);
}
Polygon* poly = new Polygon(id, type, color, shape, true, (SUMOReal)layer);
if (!toFill.insert(id, poly, layer)) {
WRITE_ERROR("Polygon '" + id + "' could not be added.");
delete poly;
if (toFill.insert(id, poly, layer)) {
parCont.push_back(poly);
}
parCont.push_back(poly);
}
break;
case wkbMultiPoint: {
Expand All @@ -194,11 +188,9 @@ PCLoaderArcView::load(const std::string& file, OptionsCont& oc, PCPolyContainer&
WRITE_ERROR("Unable to project coordinates for POI '" + tid + "'.");
}
PointOfInterest* poi = new PointOfInterest(tid, type, color, pos, (SUMOReal)layer);
if (!toFill.insert(tid, poi, layer)) {
WRITE_ERROR("POI '" + tid + "' could not be added.");
delete poi;
if (toFill.insert(tid, poi, layer)) {
parCont.push_back(poi);
}
parCont.push_back(poi);
}
}
break;
Expand All @@ -216,11 +208,9 @@ PCLoaderArcView::load(const std::string& file, OptionsCont& oc, PCPolyContainer&
shape.push_back_noDoublePos(pos);
}
Polygon* poly = new Polygon(tid, type, color, shape, false, (SUMOReal)layer);
if (!toFill.insert(tid, poly, layer)) {
WRITE_ERROR("Polygon '" + tid + "' could not be added.");
delete poly;
if (toFill.insert(tid, poly, layer)) {
parCont.push_back(poly);
}
parCont.push_back(poly);
}
}
break;
Expand All @@ -238,11 +228,9 @@ PCLoaderArcView::load(const std::string& file, OptionsCont& oc, PCPolyContainer&
shape.push_back_noDoublePos(pos);
}
Polygon* poly = new Polygon(tid, type, color, shape, true, (SUMOReal)layer);
if (!toFill.insert(tid, poly, layer)) {
WRITE_ERROR("Polygon '" + tid + "' could not be added.");
delete poly;
if (toFill.insert(tid, poly, layer)) {
parCont.push_back(poly);
}
parCont.push_back(poly);
}
}
break;
Expand All @@ -259,7 +247,7 @@ PCLoaderArcView::load(const std::string& file, OptionsCont& oc, PCPolyContainer&
if (poFieldDefn->GetType() == OFTReal) {
(*it)->addParameter(poFieldDefn->GetNameRef(), toString(poFeature->GetFieldAsDouble(iField)));
} else {
(*it)->addParameter(poFieldDefn->GetNameRef(), poFeature->GetFieldAsString(iField));
(*it)->addParameter(poFieldDefn->GetNameRef(), StringUtils::latin1_to_utf8(poFeature->GetFieldAsString(iField)));
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions sumo/src/polyconvert/PCLoaderDlrNavteq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,7 @@ PCLoaderDlrNavteq::loadPOIFile(const std::string& file,
ignorePrunning = true;
}
PointOfInterest* poi = new PointOfInterest(name, type, color, pos, (SUMOReal)layer);
if (!toFill.insert(name, poi, layer, ignorePrunning)) {
WRITE_ERROR("POI '" + name + "' could not be added.");
delete poi;
}
toFill.insert(name, poi, layer, ignorePrunning);
}
}
}
Expand Down Expand Up @@ -265,10 +262,7 @@ PCLoaderDlrNavteq::loadPolyFile(const std::string& file,
}
if (!discard) {
Polygon* poly = new Polygon(name, type, color, vec, fill, (SUMOReal)layer);
if (!toFill.insert(name, poly, layer)) {
WRITE_ERROR("Polygon '" + name + "' could not be added.");
delete poly;
}
toFill.insert(name, poly, layer);
}
vec.clear();
}
Expand Down
4 changes: 0 additions & 4 deletions sumo/src/polyconvert/PCLoaderOSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ PCLoaderOSM::addPolygon(const PCOSMEdge* edge, const PositionVector& vec, const
poly->addParameter(edge->myAttributes);
}
if (!toFill.insert(id, poly, def.layer, ignorePruning)) {
WRITE_ERROR("Polygon '" + id + "' could not be added.");
delete poly;
return index;
} else {
return index + 1;
Expand All @@ -257,8 +255,6 @@ PCLoaderOSM::addPOI(const PCOSMNode* node, const Position& pos, const PCTypeMap:
poi->addParameter(node->myAttributes);
}
if (!toFill.insert(id, poi, def.layer, ignorePruning)) {
WRITE_ERROR("POI '" + id + "' could not be added.");
delete poi;
return index;
} else {
return index + 1;
Expand Down
20 changes: 4 additions & 16 deletions sumo/src/polyconvert/PCLoaderVisum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,7 @@ PCLoaderVisum::load(const std::string& file, OptionsCont& oc, PCPolyContainer& t
}
if (!discard) {
PointOfInterest* poi = new PointOfInterest(id, type, color, pos, (SUMOReal)layer);
if (!toFill.insert(id, poi, layer)) {
WRITE_ERROR("POI '" + id + "' could not be added.");
delete poi;
}
toFill.insert(id, poi, layer);
}
}

Expand Down Expand Up @@ -281,10 +278,7 @@ PCLoaderVisum::load(const std::string& file, OptionsCont& oc, PCPolyContainer& t
}
if (!discard) {
Polygon* poly = new Polygon(id, type, color, vec, false, (SUMOReal)layer);
if (!toFill.insert(id, poly, 1)) {
WRITE_ERROR("Polygon '" + id + "' could not be added.");
delete poly;
}
toFill.insert(id, poly, 1);
}
vec.clear();
}
Expand Down Expand Up @@ -330,20 +324,14 @@ PCLoaderVisum::load(const std::string& file, OptionsCont& oc, PCPolyContainer& t
if (!discard) {
if (teilflaechen[flaechenelemente[area]].size() > 0) {
Polygon* poly = new Polygon(id, type, color, teilflaechen[flaechenelemente[area]], false, (SUMOReal)layer);
if (!toFill.insert(id, poly, layer)) {
WRITE_ERROR("Polygon '" + id + "' could not be added.");
delete poly;
}
toFill.insert(id, poly, layer);
} else {
Position pos(x, y);
if (!geoConvHelper.x2cartesian(pos)) {
WRITE_WARNING("Unable to project coordinates for POI '" + id + "'.");
}
PointOfInterest* poi = new PointOfInterest(id, type, color, pos, (SUMOReal)layer);
if (!toFill.insert(id, poi, layer)) {
WRITE_ERROR("POI '" + id + "' could not be added.");
delete poi;
}
toFill.insert(id, poi, layer);
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions sumo/src/polyconvert/PCLoaderXML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ PCLoaderXML::myStartElement(int element,
ignorePrunning = true;
}
PointOfInterest* poi = new PointOfInterest(id, type, color, pos, layer, angle, imgFile, imgWidth, imgHeight);
if (!myCont.insert(id, poi, (int)layer, ignorePrunning)) {
WRITE_ERROR("POI '" + id + "' could not be added.");
delete poi;
}
myCont.insert(id, poi, (int)layer, ignorePrunning);
}
}
if (element == SUMO_TAG_POLY) {
Expand Down Expand Up @@ -214,10 +211,7 @@ PCLoaderXML::myStartElement(int element,
shape.push_back(pos);
}
Polygon* poly = new Polygon(myCurrentID, myCurrentType, myCurrentColor, shape, fill, layer, angle, imgFile);
if (!myCont.insert(myCurrentID, poly, (int)myCurrentLayer, myCurrentIgnorePrunning)) {
WRITE_ERROR("Polygon '" + myCurrentID + "' could not be added.");
delete poly;
}
myCont.insert(myCurrentID, poly, (int)myCurrentLayer, myCurrentIgnorePrunning);
}
}
}
Expand Down
28 changes: 16 additions & 12 deletions sumo/src/polyconvert/PCPolyContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
// method definitions
// ===========================================================================
PCPolyContainer::PCPolyContainer(bool prune,
const Boundary& prunningBoundary,
const Boundary& pruningBoundary,
const std::vector<std::string>& removeByNames)
: myPrunningBoundary(prunningBoundary), myDoPrunne(prune),
: myPruningBoundary(pruningBoundary), myDoPrune(prune),
myRemoveByNames(removeByNames) {}


Expand All @@ -64,24 +64,26 @@ PCPolyContainer::~PCPolyContainer() {

bool
PCPolyContainer::insert(const std::string& id, Polygon* poly,
int layer, bool ignorePrunning) {
int layer, bool ignorePruning) {
// check whether the polygon lies within the wished area
// - if such an area was given
if (myDoPrunne && !ignorePrunning) {
if (myDoPrune && !ignorePruning) {
Boundary b = poly->getShape().getBoxBoundary();
if (!b.partialWithin(myPrunningBoundary)) {
if (!b.partialWithin(myPruningBoundary)) {
delete poly;
return true;
return false;
}
}
// check whether the polygon was named to be a removed one
if (find(myRemoveByNames.begin(), myRemoveByNames.end(), id) != myRemoveByNames.end()) {
delete poly;
return true;
return false;
}
//
PolyCont::iterator i = myPolyCont.find(id);
if (i != myPolyCont.end()) {
WRITE_ERROR("Polygon '" + id + "' could not be added.");
delete poly;
return false;
}
myPolyCont[id] = poly;
Expand All @@ -92,23 +94,25 @@ PCPolyContainer::insert(const std::string& id, Polygon* poly,

bool
PCPolyContainer::insert(const std::string& id, PointOfInterest* poi,
int layer, bool ignorePrunning) {
int layer, bool ignorePruning) {
// check whether the poi lies within the wished area
// - if such an area was given
if (myDoPrunne && !ignorePrunning) {
if (!myPrunningBoundary.around(*poi)) {
if (myDoPrune && !ignorePruning) {
if (!myPruningBoundary.around(*poi)) {
delete poi;
return true;
return false;
}
}
// check whether the polygon was named to be a removed one
if (find(myRemoveByNames.begin(), myRemoveByNames.end(), id) != myRemoveByNames.end()) {
delete poi;
return true;
return false;
}
//
POICont::iterator i = myPOICont.find(id);
if (i != myPOICont.end()) {
WRITE_ERROR("POI '" + id + "' could not be added.");
delete poi;
return false;
}
myPOICont[id] = poi;
Expand Down
44 changes: 22 additions & 22 deletions sumo/src/polyconvert/PCPolyContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ using namespace SUMO;
class PCPolyContainer {
public:
/** @brief Constructor
* @param[in] prune Whether added polygons/pois shall be prunned
* @param[in] prunningBoundary The pruning boundary (onyl valid if prune==true)
* @param[in] prune Whether added polygons/pois shall be pruned
* @param[in] pruningBoundary The pruning boundary (only valid if prune==true)
* @param[in] removeByNames Names of objects that shall not be added
*/
PCPolyContainer(bool prune, const Boundary& prunningBoundary,
PCPolyContainer(bool prune, const Boundary& pruningBoundary,
const std::vector<std::string>& removeByNames);


Expand All @@ -65,40 +65,40 @@ class PCPolyContainer {

/** @brief Adds a polygon to the storage
*
* If prunning if enabled, "ignorePrunning" is false and the polygon lies outside
* the prunning boundary, or if the polygon's name is within the names of
* objects to discard, the polygon is deleted and true is returned.
* If pruning if enabled, "ignorePruning" is false and the polygon lies outside
* the pruning boundary, or if the polygon's name is within the names of
* objects to discard, the polygon is deleted and false is returned.
*
* Otherwise, it is tested whether a polygon with the same name is already stored.
* If so, false is returned (the polygon is not deleted), otherwise true.
* Afterwards it is tested whether a polygon with the same name is already stored.
* If so, an error message is printed, the polygon is deleted and false is returned, otherwise true.
*
* @param[in] id The id of the polygon to add
* @param[in] poly The polygon to add
* @param[in] layer The layer the polygon shall be located within
* @param[in] ignorePrunning Whether the polygon shall be kept, even though it would be prunned
* @return Whether the polygon could been added (no one with the same id was added before)
* @param[in] ignorePruning Whether the polygon shall be kept, even though it would be pruned
* @return Whether the polygon could be added
*/
bool insert(const std::string& id, Polygon* poly, int layer,
bool ignorePrunning = false);
bool ignorePruning = false);


/** @brief Adds a poi to the storage
*
* If prunning if enabled, "ignorePrunning" is false and the poi lies outside
* the prunning boundary, or if the poi's name is within the names of
* objects to discard, the poi is deleted and true is returned.
* If pruning if enabled, "ignorePruning" is false and the poi lies outside
* the pruning boundary, or if the poi's name is within the names of
* objects to discard, the poi is deleted and false is returned.
*
* Otherwise, it is tested whether a poi with the same name is already stored.
* If so, false is returned (the poi is not deleted), otherwise true.
* Afterwards it is tested whether a poi with the same name is already stored.
* If so, an error message is printed, the poi is deleted and false is returned, otherwise true.
*
* @param[in] id The id of the poi to add
* @param[in] poly The poi to add
* @param[in] layer The layer the poi shall be located within
* @param[in] ignorePrunning Whether the poi shall be kept, even though it would be prunned
* @return Whether the poi could been added (no one with the same id was added before)
* @param[in] ignorePruning Whether the poi shall be kept, even though it would be pruned
* @return Whether the poi could be added
*/
bool insert(const std::string& id, PointOfInterest* poi, int layer,
bool ignorePrunning = false);
bool ignorePruning = false);


/** @brief Returns the number of stored polygons
Expand Down Expand Up @@ -175,10 +175,10 @@ class PCPolyContainer {


/// @brief The boundary that described the rectangle within which an object must be in order to be kept
Boundary myPrunningBoundary;
Boundary myPruningBoundary;

/// @brief Information whether the prunning boundary shall be used
bool myDoPrunne;
/// @brief Information whether the pruning boundary shall be used
bool myDoPrune;

/// @brief List of names of polygons/pois that shall be removed
std::vector<std::string> myRemoveByNames;
Expand Down
Loading

0 comments on commit 8d9df49

Please sign in to comment.