use of org.apache.sis.xml.NilObject in project sis by apache.
the class DefaultExtent method intersect.
/**
* Sets this extent to the intersection of this extent with the specified one.
* This method computes the intersections of all geographic, vertical and temporal elements in this extent
* with all geographic, vertical and temporal elements in the other extent, ignoring duplicated results.
*
* @param other the extent to intersect with this extent.
* @throws IllegalArgumentException if two elements to intersect are not compatible (e.g. mismatched
* {@linkplain DefaultGeographicBoundingBox#getInclusion() bounding box inclusion status} or
* mismatched {@linkplain DefaultVerticalExtent#getVerticalCRS() vertical datum}).
* @throws UnsupportedOperationException if a {@code TemporalFactory} is required but no implementation
* has been found on the classpath.
*
* @see Extents#intersection(Extent, Extent)
* @see org.apache.sis.geometry.GeneralEnvelope#intersect(Envelope)
*
* @since 0.8
*/
public void intersect(final Extent other) {
checkWritePermission();
ArgumentChecks.ensureNonNull("other", other);
final InternationalString od = other.getDescription();
if (od != null && !(description instanceof NilObject)) {
if (description == null || (od instanceof NilObject)) {
description = od;
} else if (!description.equals(od)) {
description = NilReason.MISSING.createNilObject(InternationalString.class);
}
}
geographicElements = intersect(GeographicExtent.class, geographicElements, other.getGeographicElements(), Extents::intersection);
verticalElements = intersect(VerticalExtent.class, verticalElements, other.getVerticalElements(), Extents::intersection);
temporalElements = intersect(TemporalExtent.class, temporalElements, other.getTemporalElements(), Extents::intersection);
}
use of org.apache.sis.xml.NilObject in project sis by apache.
the class DefaultTemporalExtent method intersect.
/**
* Sets this temporal extent to the intersection of this extent with the specified one.
* If there is no intersection between the two extents, then this method sets the temporal primitive to nil.
* If either this extent or the specified extent has nil primitive, then the intersection result will also be nil.
*
* @param other the temporal extent to intersect with this extent.
* @throws UnsupportedOperationException if no implementation of {@code TemporalFactory} has been found
* on the classpath.
*
* @see Extents#intersection(TemporalExtent, TemporalExtent)
* @see org.apache.sis.geometry.GeneralEnvelope#intersect(Envelope)
*
* @since 0.8
*/
public void intersect(final TemporalExtent other) {
checkWritePermission();
final TemporalPrimitive ot = other.getExtent();
if (ot != null && !(extent instanceof NilObject)) {
if (extent == null || (ot instanceof NilObject)) {
extent = ot;
} else {
Date t0 = getTime(extent, true);
Date t1 = getTime(extent, false);
Date h0 = getTime(ot, true);
Date h1 = getTime(ot, false);
boolean changed = false;
if (h0 != null && (t0 == null || h0.after(t0))) {
t0 = h0;
changed = true;
}
if (h1 != null && (t1 == null || h1.before(t1))) {
t1 = h1;
changed = true;
}
if (changed) {
if (t0 != null && t1 != null && t0.after(t1)) {
extent = NilReason.MISSING.createNilObject(TemporalPrimitive.class);
} else {
setBounds(t0, t1);
}
}
}
}
}
use of org.apache.sis.xml.NilObject in project sis by apache.
the class DefaultExtentTest method testIntersect.
/**
* Tests {@link DefaultExtent#intersect(Extent)}.
*/
@Test
public void testIntersect() {
final DefaultGeographicBoundingBox bounds1 = new DefaultGeographicBoundingBox(10, 20, 30, 40);
final DefaultGeographicBoundingBox bounds2 = new DefaultGeographicBoundingBox(16, 18, 31, 42);
final DefaultGeographicBoundingBox clip = new DefaultGeographicBoundingBox(15, 25, 26, 32);
final DefaultGeographicBoundingBox expected1 = new DefaultGeographicBoundingBox(15, 20, 30, 32);
final DefaultGeographicBoundingBox expected2 = new DefaultGeographicBoundingBox(16, 18, 31, 32);
final DefaultExtent e1 = new DefaultExtent("Somewhere", bounds1, null, null);
final DefaultExtent e2 = new DefaultExtent("Somewhere", clip, null, null);
e1.getGeographicElements().add(bounds2);
e1.intersect(e2);
assertEquals("description", "Somewhere", e1.getDescription().toString());
assertFalse("isNil(description)", e1.getDescription() instanceof NilObject);
assertArrayEquals("geographicElements", new DefaultGeographicBoundingBox[] { expected1, expected2 }, e1.getGeographicElements().toArray());
/*
* Change the description and test again. That description should be considered missing
* because we have a mismatch. Also change abounding box in such a way that there is no
* intersection. That bounding box should be omitted.
*/
bounds2.setBounds(8, 12, 33, 35);
e1.setGeographicElements(Arrays.asList(bounds1, bounds2));
e2.setDescription(new SimpleInternationalString("Somewhere else"));
e1.intersect(e2);
assertTrue("isNil(description)", e1.getDescription() instanceof NilObject);
assertArrayEquals("geographicElements", new DefaultGeographicBoundingBox[] { expected1 }, e1.getGeographicElements().toArray());
}
Aggregations