Package mil.nga.giat.geowave.vector.plugin

Source Code of mil.nga.giat.geowave.vector.plugin.WFSSpatialTest

package mil.nga.giat.geowave.vector.plugin;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.text.ParseException;
import java.util.UUID;

import mil.nga.giat.geowave.vector.utils.DateUtilities;

import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.geotools.data.DataUtilities;
import org.geotools.data.DefaultTransaction;
import org.geotools.data.FeatureReader;
import org.geotools.data.FeatureWriter;
import org.geotools.data.Query;
import org.geotools.data.Transaction;
import org.geotools.feature.SchemaException;
import org.geotools.filter.text.cql2.CQL;
import org.geotools.filter.text.cql2.CQLException;
import org.junit.Before;
import org.junit.Test;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.PrecisionModel;

public class WFSSpatialTest
{
  GeoWaveGTMemDataStore dataStore;
  SimpleFeatureType schema;
  SimpleFeatureType type;
  GeometryFactory factory = new GeometryFactory(
      new PrecisionModel(
          PrecisionModel.FIXED));
  Query query = null;

  @Before
  public void setup()
      throws AccumuloException,
      AccumuloSecurityException,
      SchemaException,
      CQLException {
    dataStore = new GeoWaveGTMemDataStore();
    type = DataUtilities.createType(
        "geostuff",
        "geometry:Geometry:srid=4326,pop:java.lang.Long,when:Date,pid:String");

    dataStore.createSchema(type);
    query = new Query(
        "geostuff",
        CQL.toFilter("BBOX(geometry,27.20,41.30,27.30,41.20) and when during 2005-05-19T20:32:56Z/2005-05-19T21:32:56Z"),
        new String[] {
          "geometry",
          "pid"
        });
  }

  @Test
  public void test()
      throws IOException,
      CQLException,
      ParseException {
    Transaction transaction1 = new DefaultTransaction();

    FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(
        type.getTypeName(),
        transaction1);
    assertFalse(writer.hasNext());
    SimpleFeature newFeature = writer.next();
    newFeature.setAttribute(
        "pop",
        new Long(
            100));
    newFeature.setAttribute(
        "pid",
        UUID.randomUUID().toString());
    newFeature.setAttribute(
        "when",
        DateUtilities.parseISO("2005-05-19T18:33:55Z"));
    newFeature.setAttribute(
        "geometry",
        factory.createPoint(new Coordinate(
            27.25,41.25)));

    newFeature = writer.next();
    newFeature.setAttribute(
        "pop",
        new Long(
            100));
    newFeature.setAttribute(
        "pid",
        UUID.randomUUID().toString());
    newFeature.setAttribute(
        "when",
        DateUtilities.parseISO("2005-05-19T20:33:55Z"));
    newFeature.setAttribute(
        "geometry",
        factory.createPoint(new Coordinate(
            27.25,41.25)));
    writer.write();
    writer.close();

    FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(
        query,
        transaction1);
    assertTrue(reader.hasNext());
    SimpleFeature priorFeature = reader.next();
    assertEquals(
        newFeature.getAttribute("pid"),
        priorFeature.getAttribute("pid"));
    assertFalse(reader.hasNext());
    reader.close();

    transaction1.commit();
    transaction1.close();

  }
}
TOP

Related Classes of mil.nga.giat.geowave.vector.plugin.WFSSpatialTest

TOP
Copyright © 2018 www.massapi.com. 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.