use of org.openstreetmap.osmosis.core.domain.v0_6.Bound in project osmosis by openstreetmap.
the class BoundsElementProcessor method begin.
/**
* {@inheritDoc}
*/
@Override
public void begin(Attributes attributes) {
double bottom = getRequiredDoubleValue(attributes, XmlConstants.ATTRIBUTE_NAME_MINLAT);
double left = getRequiredDoubleValue(attributes, XmlConstants.ATTRIBUTE_NAME_MINLON);
double top = getRequiredDoubleValue(attributes, XmlConstants.ATTRIBUTE_NAME_MAXLAT);
double right = getRequiredDoubleValue(attributes, XmlConstants.ATTRIBUTE_NAME_MAXLON);
String origin = attributes.getValue(XmlConstants.ATTRIBUTE_NAME_ORIGIN);
if (origin == null) {
origin = defaultOrigin;
}
bound = new Bound(right, left, top, bottom, origin);
}
use of org.openstreetmap.osmosis.core.domain.v0_6.Bound in project osmosis by openstreetmap.
the class FastXmlParser method readBound.
private Bound readBound() throws Exception {
String boxString;
String origin;
String[] boundStrings;
Double right;
Double left;
Double top;
Double bottom;
boxString = reader.getAttributeValue(null, ATTRIBUTE_NAME_BOX);
if (boxString == null) {
throw new OsmosisRuntimeException("Missing required box attribute of bound element");
}
boundStrings = boxString.split(",");
if (boundStrings.length != 4) {
throw new OsmosisRuntimeException("Badly formed box attribute of bound element");
}
try {
bottom = Double.parseDouble(boundStrings[0]);
left = Double.parseDouble(boundStrings[1]);
top = Double.parseDouble(boundStrings[2]);
right = Double.parseDouble(boundStrings[3]);
} catch (NumberFormatException e) {
throw new OsmosisRuntimeException("Can't parse box attribute of bound element", e);
}
origin = reader.getAttributeValue(null, ATTRIBUTE_NAME_ORIGIN);
if (origin == null || origin.equals("")) {
throw new OsmosisRuntimeException("Origin attribute of bound element is empty or missing.");
}
Bound bound = new Bound(right, left, top, bottom, origin);
reader.nextTag();
reader.nextTag();
return bound;
}
use of org.openstreetmap.osmosis.core.domain.v0_6.Bound in project osmosis by openstreetmap.
the class LegacyBoundElementProcessor method begin.
/**
* {@inheritDoc}
*/
@Override
public void begin(Attributes attributes) {
String boxString;
String origin;
String[] boundStrings;
Double right;
Double left;
Double top;
Double bottom;
boxString = attributes.getValue(ATTRIBUTE_NAME_BOX);
if (boxString == null) {
throw new OsmosisRuntimeException("Missing required box attribute of bound element");
}
boundStrings = boxString.split(",");
if (boundStrings.length != 4) {
throw new OsmosisRuntimeException("Badly formed box attribute of bound element");
}
try {
bottom = Double.parseDouble(boundStrings[0]);
left = Double.parseDouble(boundStrings[1]);
top = Double.parseDouble(boundStrings[2]);
right = Double.parseDouble(boundStrings[3]);
} catch (NumberFormatException e) {
throw new OsmosisRuntimeException("Can't parse box attribute of bound element", e);
}
origin = attributes.getValue(ATTRIBUTE_NAME_ORIGIN);
if (origin == null || origin.equals("")) {
throw new OsmosisRuntimeException("Origin attribute of bound element is empty or missing.");
}
bound = new Bound(right, left, top, bottom, origin);
}
use of org.openstreetmap.osmosis.core.domain.v0_6.Bound in project osmosis by openstreetmap.
the class MergeBoundTest method testBothHaveBounds.
/**
* Test the proper computation of the union bound iff both sources
* have bounds.
*
* @throws Exception if something goes wrong
*/
@Test
public void testBothHaveBounds() throws Exception {
Bound bound0 = new Bound(1, 2, 4, 3, "source1");
RunnableSource source0 = new BoundSource(bound0, true);
Bound bound1 = new Bound(5, 6, 8, 7, "source2");
RunnableSource source1 = new BoundSource(bound1, true);
EntityMerger merger = new EntityMerger(ConflictResolutionMethod.LatestSource, 1, BoundRemovedAction.Ignore);
SinkEntityInspector merged = RunTaskUtilities.run(merger, source0, source1);
List<EntityContainer> mergedList = createList(merged.getProcessedEntities());
Assert.assertEquals(3, mergedList.size());
Assert.assertEquals(EntityType.Bound, mergedList.get(0).getEntity().getType());
// Check the bound
Bound bound01 = (Bound) mergedList.get(0).getEntity();
Assert.assertEquals(bound0.union(bound1), bound01);
for (int i = 1; i < mergedList.size(); i++) {
Assert.assertEquals(EntityType.Node, mergedList.get(i).getEntity().getType());
}
}
use of org.openstreetmap.osmosis.core.domain.v0_6.Bound in project osmosis by openstreetmap.
the class OsmHandlerTest method testBoundsNoOrigin.
/**
* Test the parsing of a bound element as returned by the OSM API
* without an origin.
*/
@Test
public void testBoundsNoOrigin() {
parseString(OSM_PREFIX + "<bounds minlat=\"-1.234\" minlon=\"-1.234\" maxlat=\"1.234\" maxlon=\"1.234\"/>" + OSM_SUFFIX);
Bound b = (Bound) entityInspector.getLastEntityContainer().getEntity();
assertEquals(-1.234, b.getLeft(), 1E-6);
assertEquals(-1.234, b.getBottom(), 1E-6);
assertEquals(1.234, b.getRight(), 1E-6);
assertEquals(1.234, b.getTop(), 1E-6);
assertNull(b.getOrigin());
}
Aggregations