Package org.geotools.measure

Examples of org.geotools.measure.Measure


    public Measure distance(final double[] coord1, final double[] coord2)
            throws MismatchedDimensionException
    {
        ensureDimensionMatch("coord1", coord1);
        ensureDimensionMatch("coord2", coord2);
        return new Measure(Math.abs(coord1[0] - coord2[0]), getDistanceUnit());
    }
View Full Code Here


        throws Exception {
        Double d = Double.valueOf(node.getComponent().getText());
        URI uom = (URI) node.getAttributeValue(URI.class);

        if (uom != null) {
            return new Measure(d.doubleValue(), new BaseUnit(uom.toString()) {
                });
        }

        return new Measure(d.doubleValue(), null);
    }
View Full Code Here

        return new Measure(d.doubleValue(), null);
    }

    public Element encode(Object object, Document document, Element value)
        throws Exception {
        Measure measure = (Measure) object;
        value.appendChild(document.createTextNode("" + measure.doubleValue()));

        return value;
    }
View Full Code Here

    }

    public Object getProperty(Object object, QName name)
        throws Exception {
        if ("uom".equals(name.getLocalPart())) {
            Measure measure = (Measure) object;

            if (measure.getUnit() != null) {
                return new URI(((BaseUnit) measure.getUnit()).getSymbol());
            }
        }

        return null;
    }
View Full Code Here

   
    public void testParser() throws Exception {
        GML3MockData.element(GML.measure, document, document);
        document.getDocumentElement().setAttribute("uom", "http://someuri");
        document.getDocumentElement().appendChild(document.createTextNode("1234"));
        Measure measure = (Measure) parse();
        assertNotNull(measure);
        assertEquals(1234, measure.doubleValue(), 0.1);
        assertEquals("http://someuri", ((BaseUnit) measure.getUnit()).getSymbol());
    }
View Full Code Here

        for (int i=crs.getCoordinateSystem().getDimension(); --i>=0;) {
            table.nextColumn();
        }
        if (position2 != null) {
            if (crs instanceof AbstractCRS) try {
                final Measure distance;
                distance = ((AbstractCRS)crs).distance(position1.getCoordinate(),
                                                       position2.getCoordinate());
                table.setAlignment(TableWriter.ALIGN_RIGHT);
                table.write(numberFormat.format(distance.doubleValue()));
                table.write("  ");
                table.nextColumn();
                table.write(String.valueOf(distance.getUnit()));
                table.setAlignment(TableWriter.ALIGN_LEFT);
                return;
            } catch (UnsupportedOperationException ignore) {
                /*
                 * Underlying CRS do not supports distance computation.
View Full Code Here

                    double[] geo1 = new double[2];
                    crsTransform.transform(co0, 0, geo0, 0, 1);
                    crsTransform.transform(co1, 0, geo1, 0, 1);

                    // get distance
                    Measure m = DefaultGeographicCRS.WGS84.distance(geo0, geo1);
                    if (m.doubleValue() > nearestDistance)
                        continue;
                    nearestFeature = f;
                    nearestDistance = m.doubleValue();
                    nearestBearing = calcBearing(co);
                    nearestPoint[0] = geo1[0];
                    nearestPoint[1] = geo1[1];
                }
            } finally {
View Full Code Here

                    double[] geo1 = new double[2];
                    crsTransform.transform(co0, 0, geo0, 0, 1);
                    crsTransform.transform(co1, 0, geo1, 0, 1);

                    // get distance
                    Measure m = DefaultGeographicCRS.WGS84.distance(geo0, geo1);
                    if (m.doubleValue() > nearestDistance)
                        continue;
                    nearestFeature = f;
                    nearestDistance = m.doubleValue();
                    nearestBearing = calcBearing(co);
                }
            } finally {
                if (featureIterator != null)
                    featureCollection.close(featureIterator);
View Full Code Here

        int coordCountDefault = coords.split("\\s+").length;

        // now alter the feature type and set a linearization tolerance
        FeatureTypeInfo ft = getCatalog().getFeatureTypeByName(getLayerId(CURVELINES));
        ft.setCircularArcPresent(true);
        ft.setLinearizationTolerance(new Measure(1, SI.METER));
        getCatalog().save(ft);

        dom = getAsDOM("wfs?service=wfs&version=1.0&request=GetFeature&typeName="
                + getLayerId(CURVELINES));
        // print(dom);
View Full Code Here

        }
    }
   
    private Double getTolerance(FeatureTypeInfo info) {
      // get the measure, if null, no linearization tolerance is available
    Measure mt = info.getLinearizationTolerance();
    if(mt == null) {
      return null;
    }
   
    // if the user did not specify a unit of measure, we use it as an absolute value
    if(mt.getUnit() == null) {
      return mt.doubleValue();
    }
   
    // should not happen, but let's cover all our bases
    CoordinateReferenceSystem crs = info.getCRS();
    if(crs == null) {
      return mt.doubleValue();
    }
   
    // let's get the target unit
    SingleCRS horizontalCRS = CRS.getHorizontalCRS(crs);
    Unit targetUnit;
    if(horizontalCRS != null) {
      // leap of faith, the first axis is an horizontal one (
      targetUnit = getFirstAxisUnit(horizontalCRS.getCoordinateSystem());
    } else {
      // leap of faith, the first axis is an horizontal one (
      targetUnit = getFirstAxisUnit(crs.getCoordinateSystem());
    }
   
    if((targetUnit != null && targetUnit == NonSI.DEGREE_ANGLE) || horizontalCRS instanceof GeographicCRS || crs instanceof GeographicCRS) {
      // assume we're working against a type of geographic crs, must estimate the degrees equivalent
      // to the measure, we are going to use a very rough estimate (cylindrical earth model)
      // TODO: maybe look at the layer bbox and get a better estimate computed at the center of the bbox
      UnitConverter converter = mt.getUnit().getConverterTo(SI.METER);
      double tolMeters = converter.convert(mt.doubleValue());
      return tolMeters * OGC_METERS_TO_DEGREES;
    } else if(targetUnit != null && targetUnit.isCompatible(SI.METER)) {
      // ok, we assume the target is not a geographic one, but we might
      // have to convert between meters and feet maybe
      UnitConverter converter = mt.getUnit().getConverterTo(targetUnit);
      return converter.convert(mt.doubleValue());
    } else {
      return mt.doubleValue();
    }
   
  }
View Full Code Here

TOP

Related Classes of org.geotools.measure.Measure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.