Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activate GeojsonWriter tests #73

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 30 additions & 39 deletions include/IO/Writer/GeojsonWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ class GeoJsonWriter final {
, TGraph const & graph )
{
WriteHeader ( os );
WriteFeatureCollection ( os );
WriteFeaturesBegin ( os );
WriteVertices ( os, graph, false);
WriteLines ( os, graph, true );
WriteFeaturesEnd ( os, true );
WriteFeaturesEnd ( os, false );
WriteFeatureCollection ( os/*, true*/ );
WriteFooter ( os );
return true; // How do you declare success
}
Expand Down Expand Up @@ -178,10 +178,6 @@ class GeoJsonWriter final {
Indent( os, indent );
os << "{";
NewLine(os);

Indent( os, indent + 1 );
os << "\"type\": \"Feature\",";
NewLine(os);
}

/**
Expand All @@ -195,6 +191,9 @@ class GeoJsonWriter final {
, bool last = false
, Types::count indent = 1 )
{
Indent( os, indent + 1 );
os << "\"type\": \"Feature\",";
NewLine(os);
char comma = last?' ':',';
Indent( os, indent );
os << "}"
Expand All @@ -218,7 +217,7 @@ class GeoJsonWriter final {
}

/**
* @brief Writes vertex properties.
* @brief Writes vertex properties in alphabetic order.
*
* @param os The output stream.
* @param vertexProperty The vertex property.
Expand All @@ -229,33 +228,24 @@ class GeoJsonWriter final {
, Types::count indent = 2 )
{
bool last = false;
/* Basic Property Members */
PropertyTemplate<Types::name> ( os, "name", vertexProperty.Name(), last, indent );
PropertyTemplate<TVertexType> ( os, "type", vertexProperty.Type(), last, indent );
PropertyTemplate<Types::real> ( os, "xCoordinate", vertexProperty.X(), last, indent );
PropertyTemplate<Types::real> ( os, "yCoordinate", vertexProperty.Y(), last, indent );

/* Admittance Related Members */
PropertyTemplate<Types::real> ( os, "shuntConductance", vertexProperty.ShuntConductance(), last, indent );
PropertyTemplate<Types::real> ( os, "shuntSusceptance", vertexProperty.ShuntSusceptance(), last, indent );

/* Voltage Related Members */
PropertyTemplate<Types::real> ( os, "voltageMagnitude", vertexProperty.VoltageMagnitude(), last, indent );
PropertyTemplate<Types::real> ( os, "voltageAngle", vertexProperty.VoltageAngle(), last, indent );
PropertyTemplate<Types::real> ( os, "nominalVoltage", vertexProperty.NominalVoltage(), last, indent );
PropertyTemplate<Types::real> ( os, "maximumVoltage", vertexProperty.MaximumVoltage(), last, indent );
PropertyTemplate<Types::real> ( os, "minimumVoltage", vertexProperty.MinimumVoltage(), last, indent );

/* Location Specific Members */
PropertyTemplate<Types::name> ( os, "country", vertexProperty.Country(), last, indent );
PropertyTemplate<Types::index> ( os, "area", vertexProperty.Area(), last, indent );
PropertyTemplate<Types::index> ( os, "zone", vertexProperty.Zone(), last, indent );
PropertyTemplate<Vertices::ControlType> ( os, "control", vertexProperty.Control(), last, indent );
PropertyTemplate<Vertices::EnergyCarrier> ( os, "carrier", vertexProperty.Carrier(), last, indent );

/* Status Members */
PropertyTemplate<Types::index> ( os, "area", vertexProperty.Area(), last, indent ); /* Location Specific Members */
PropertyTemplate<Vertices::EnergyCarrier> ( os, "carrier", vertexProperty.Carrier(), last, indent ); /* Location Specific Members */
PropertyTemplate<Vertices::ControlType> ( os, "control", vertexProperty.Control(), last, indent ); /* Location Specific Members */
PropertyTemplate<Types::name> ( os, "country", vertexProperty.Country(), last, indent ); /* Location Specific Members */
PropertyTemplate<Types::real> ( os, "maximumVoltage", vertexProperty.MaximumVoltage(), last, indent ); /* Voltage Related Members */
PropertyTemplate<Types::real> ( os, "minimumVoltage", vertexProperty.MinimumVoltage(), last, indent ); /* Voltage Related Members */
PropertyTemplate<Types::name> ( os, "name", vertexProperty.Name(), last, indent ); /* Basic Property Members */
PropertyTemplate<Types::real> ( os, "nominalVoltage", vertexProperty.NominalVoltage(), last, indent ); /* Voltage Related Members */
PropertyTemplate<Types::real> ( os, "shuntConductance", vertexProperty.ShuntConductance(), last, indent ); /* Admittance Related Members */
PropertyTemplate<Types::real> ( os, "shuntSusceptance", vertexProperty.ShuntSusceptance(), last, indent ); /* Admittance Related Members */
PropertyTemplate<Vertices::BusStatus> ( os, "status", vertexProperty.Status(), last, indent ); /* Status Members */
PropertyTemplate<TVertexType> ( os, "type", vertexProperty.Type(), last, indent ); /* Basic Property Members */
PropertyTemplate<Types::real> ( os, "voltageAngle", vertexProperty.VoltageAngle(), last, indent ); /* Voltage Related Members */
PropertyTemplate<Types::real> ( os, "voltageMagnitude", vertexProperty.VoltageMagnitude(), last, indent ); /* Voltage Related Members */
PropertyTemplate<Types::real> ( os, "xCoordinate", vertexProperty.X(), last, indent ); /* Basic Property Members */
PropertyTemplate<Types::real> ( os, "yCoordinate", vertexProperty.Y(), last, indent ); /* Basic Property Members */
last = true;
PropertyTemplate<Vertices::BusStatus> ( os, "status", vertexProperty.Status(), last, indent );
PropertyTemplate<Types::index> ( os, "zone", vertexProperty.Zone(), last, indent ); /* Location Specific Members */
}

/**
Expand Down Expand Up @@ -367,7 +357,7 @@ class GeoJsonWriter final {
*/
inline void WriteFeatureCollection ( std::ostream & os )
{
os << "\"type\": \"FeatureCollection\",";
os << "\"type\": \"FeatureCollection\"";
NewLine(os);
}

Expand Down Expand Up @@ -433,10 +423,10 @@ class GeoJsonWriter final {
{
graph.for_all_vertices( [this, &os, &last, &indent]( TVertex const & vertex ){
WriteFeatureBegin ( os, indent );
WritePoint ( os, vertex, indent + 1 );
WritePropertiesBegin ( os, indent + 1 );
WriteVertexProperties ( os, vertex.Properties(), indent + 2 );
WritePropertiesEnd ( os, false, indent + 1 );
WritePoint ( os, vertex, indent + 1 );
WriteFeatureEnd ( os, last, indent );
});
}
Expand Down Expand Up @@ -465,7 +455,7 @@ class GeoJsonWriter final {
}

/**
* @brief Writes a GeoJson point.
* @brief Writes a GeoJson point in alphabetic order.
*
* @param os The output stream.
* @param[in] xCoordinate The coordinate.
Expand All @@ -481,13 +471,14 @@ class GeoJsonWriter final {
NewLine(os);

Indent( os, indent + 1 );
os << "\"type\": \"Point\",";
os << "\"coordinates\": ";
WritePointCoordinate ( os, xCoordinate, yCoordinate, 0 );
NewLine(os);

Indent( os, indent + 1 );
os << "\"coordinates\": ";
WritePointCoordinate ( os, xCoordinate, yCoordinate, 0 );
os << "\"type\": \"Point\",";
NewLine(os);

Indent( os, indent );
os << "}";
NewLine(os);
Expand Down
6 changes: 3 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@ add_test(NAME TestBlockCutTree COMMAND TestBlockCutTree)
# target_link_libraries(TestPyPsaParser EGOA gtest gtest_main gmock_main)
# add_test(NAME TestPyPsaParser COMMAND TestPyPsaParser)

# add_executable(TestGeojsonWriter IO/TestGeojsonWriter.cpp)
# target_link_libraries(TestGeojsonWriter EGOA gtest gtest_main gmock_main)
# add_test(NAME TestGeojsonWriter COMMAND TestGeojsonWriter)
add_executable(TestGeojsonWriter IO/TestGeojsonWriter.cpp)
target_link_libraries(TestGeojsonWriter EGOA gtest gtest_main gmock_main)
add_test(NAME TestGeojsonWriter COMMAND TestGeojsonWriter)
6 changes: 3 additions & 3 deletions tests/IO/TestGeojsonWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class TestGeojsonExample : public TestGeojsonWriter {
}
}

Types::string const TestCaseSmallExampleInput_ = "../../framework/tests/Data/PowerGrids/PyPsaExampleGeoJsonWriter";
Types::string const TestCaseSmallExampleExpectedOutput_ = "../../framework/tests/Data/Output/PyPsaExampleJsonWriterExpectedOutput.json";
Types::string const TestCaseSmallExampleOutputFile_ = "../../framework/tests/Data/Output/PyPsaExampleJsonWriter.json";
Types::string const TestCaseSmallExampleInput_ = "../../tests/Data/PowerGrids/PyPSAExampleGeoJsonWriter";
Types::string const TestCaseSmallExampleExpectedOutput_ = "../../tests/Data/Output/PyPsaExampleJsonWriterExpectedOutput.json";
Types::string const TestCaseSmallExampleOutputFile_ = "../../tests/Data/Output/PyPSAExampleJsonWriter.json";
};


Expand Down
Loading