Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [geomesa-users] Accumulo Writing Exception...

Thanks, I tried accumulo1.5.x/1.x branch and it is working correctly.

Regards,
Adnan


On Fri, May 30, 2014 at 6:11 PM, Anthony Fox <anthonyfox@xxxxxxxx> wrote:
Adnan,

I just tried out writing the LineStrings you mentioned - everything worked fine for me.  I was able to write using both a FeatureWriter and a FeatureStore.  This is on the tip of the accumulo1.5.x/1.x branch.  Can you double check that you're not on the master branch?  We recently switched branch naming schemes to accommodate supporting multiple versions of accumulo from one version of GeoMesa.

Thanks,
Anthony


On Fri, May 30, 2014 at 1:44 AM, Adnan Yaqoob <nsyaqoob@xxxxxxxxx> wrote:
Thanks for reply, I am using following strings with latest geomesa (1.0.0-SNAPSHOT):

POINT (30 10)
LINESTRING (30 10, 10 30, 40 40)
POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))

here is the complete code:

package AccumuloTest;

import java.util.Map;
import java.util.HashMap;
import java.io.Serializable;
import java.io.IOException;
import java.util.Date;

import org.geotools.filter.text.cql2.CQLException;
import org.geotools.filter.text.ecql.ECQL;
import org.geotools.data.Query;
import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.FeatureSource;
import org.geotools.feature.FeatureIterator;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.filter.Filter;
import org.geotools.feature.SchemaException;
import org.geotools.data.DataUtilities;
import org.geotools.feature.DefaultFeatureCollection;
import org.geotools.data.FeatureStore;
import org.geotools.factory.Hints;
import com.vividsolutions.jts.io.WKTReader;
import com.vividsolutions.jts.io.ParseException;

import geomesa.core.index.Constants;
import geomesa.utils.geotools.ShapefileIngest;

public class ATest {

    public static void main(String[] args)
    {
        try
        {
            ATest test = new ATest();
            DataStore data_store = test.createDataStore();
            SimpleFeatureType feature_type = test.createFeatureType(data_store);
            SimpleFeature  feature = test.createFeature("Product", data_store);
            test.writeFeature("Product", feature, data_store);
        }
        catch(IOException ioe)
        {
            System.out.println("\n[AccumuloTest]IOException Occured.\n");
            ioe.printStackTrace();
        }
        catch(SchemaException se)
        {
            System.out.println("\n[AccumuloTest]SchemaException Occured.\n");
            se.printStackTrace();
        }
        catch(ParseException pe)
        {
            System.out.println("\n[AccumuloTest]ParseException Occured.\n");
            pe.printStackTrace();
        }
        catch(Exception e)
        {
            System.out.println("\n[AccumuloTest]Java Exception Occured.\n");
            e.printStackTrace();
        }

    }

    public DataStore createDataStore() throws IOException {
 // build the map of parameters
        Map<String,Serializable> params = new HashMap<String,Serializable>();
        params.put("instanceId", "accumulo");
        params.put("zookeepers" , "telecom:2181");
        params.put("user","root");
        params.put("password","root");
        //params.put("auths","");
        params.put("tableName","accumulo_test");
 // fetch the data store from the finder
        return DataStoreFinder.getDataStore(params);
    }

    public SimpleFeatureType createFeatureType(DataStore dataStore) throws IOException, SchemaException {
 // name of the feature to create
        String featureName = "Product";
 // create the feature-type (a "schema" in GeoTools parlance)
 // (will also create the Accumulo table, if it does not already exist)
        String featureSchema = "NAME:String,SKU:java.lang.Long,COST:Double,SELL_BY:Date,*geom:LineString:srid=4326";
        SimpleFeatureType featureType = DataUtilities.createType(featureName, featureSchema);
        dataStore.createSchema(featureType);
        return featureType;
    }

    public SimpleFeature createFeature(String featureName, DataStore dataStore) throws IOException, ParseException {
 // fetch the feature-type corresponding to this name
        SimpleFeatureType featureType = dataStore.getSchema(featureName);
 // create the feature
        Object[] noValues = {};
        SimpleFeature newFeature = SimpleFeatureBuilder.build(featureType, noValues, "SomeNewProductID");
 // initialize a few fields
        newFeature.setDefaultGeometry((new WKTReader()).read("LINESTRING (30 10, 10 30, 40 40)"));
        newFeature.setAttribute("NAME", "New Product Name");
        newFeature.setAttribute("SKU", "011235813");
        newFeature.setAttribute("COST", 1.23);
        newFeature.setAttribute("SELL_BY", new Date());
 // start-date can be NULL, but end-date must not be
        //newFeature.setAttribute(Constants.SF_PROPERTY_START_TIME, new Date());
        //newFeature.setAttribute(Constants.SF_PROPERTY_END_TIME, new Date());
        return newFeature;
    }

    public void writeFeature(String featureName, SimpleFeature feature,DataStore dataStore) throws Exception {
 // get a feature store
        FeatureSource featureSource = dataStore.getFeatureSource(featureName);
        if (!(featureSource instanceof FeatureStore))
            throw new Exception("Could not retrieve feature store");
        FeatureStore featureStore = (FeatureStore)featureSource;
 // preserve the ID that we created for this feature
 // (set the hint to FALSE to have GeoTools generate IDs)
        feature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE);
 // create a feature collection
        DefaultFeatureCollection features = new DefaultFeatureCollection();
        features.add(feature);
 // write this feature collection to the store
        featureStore.addFeatures(features);
    }

}

Regards,
Adnan


On Thu, May 29, 2014 at 7:21 PM, Chris Snider <chris.snider@xxxxxxxxxx> wrote:

Hi,

 

Do you have an example of the line strings that are failing?

 

Chris Snider

Senior Software Engineer

Intelligent Software Solutions, Inc.

Description: Description: Description: cid:image001.png@01CA1F1F.CBC93990

 

From: geomesa-users-bounces@xxxxxxxxxxxxxxxx [mailto:geomesa-users-bounces@xxxxxxxxxxxxxxxx] On Behalf Of Adnan Yaqoob
Sent: Thursday, May 29, 2014 4:40 AM
To: Geomesa User discussions
Subject: [geomesa-users] Accumulo Writing Exception...

 

Hello,

 

I am trying to write simple LineString to Accumulo using Geomesa. I have used the schema and code provided in Geomesa documentation and I am getting following error:

 

java.lang.Exception: Invalid geometry

at geomesa.utils.geohash.GeohashUtils$.reconstructGeohashFromGeometry(GeohashUtils.scala:599)

at geomesa.core.index.IndexEntry$IndexEntrySFT.gh$lzycompute(IndexSchema.scala:193)

at geomesa.core.index.IndexEntry$IndexEntrySFT.gh(IndexSchema.scala:193)

at geomesa.core.index.GeoHashTextFormatter.format(Formatters.scala:51)

at geomesa.core.index.GeoHashTextFormatter.format(Formatters.scala:49)

at geomesa.core.index.CompositeTextFormatter$anonfun$format$2.apply(Formatters.scala:119)

at geomesa.core.index.CompositeTextFormatter$anonfun$format$2.apply(Formatters.scala:119)

at scala.collection.TraversableLike$anonfun$map$1.apply(TraversableLike.scala:244)

at scala.collection.TraversableLike$anonfun$map$1.apply(TraversableLike.scala:244)

at scala.collection.immutable.List.foreach(List.scala:318)

at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)

at scala.collection.AbstractTraversable.map(Traversable.scala:105)

at geomesa.core.index.CompositeTextFormatter.format(Formatters.scala:119)

at geomesa.core.index.IndexEncoder$anonfun$6$anonfun$7.apply(IndexSchema.scala:245)

at geomesa.core.index.IndexEncoder$anonfun$6$anonfun$7.apply(IndexSchema.scala:245)

at scala.collection.TraversableLike$anonfun$map$1.apply(TraversableLike.scala:244)

at scala.collection.TraversableLike$anonfun$map$1.apply(TraversableLike.scala:244)

at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)

at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:108)

at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)

at scala.collection.mutable.ArrayOps$ofRef.map(ArrayOps.scala:108)

at geomesa.core.index.IndexEncoder$anonfun$6.apply(IndexSchema.scala:245)

at geomesa.core.index.IndexEncoder$anonfun$6.apply(IndexSchema.scala:244)

at scala.collection.TraversableLike$anonfun$map$1.apply(TraversableLike.scala:244)

at scala.collection.TraversableLike$anonfun$map$1.apply(TraversableLike.scala:244)

at scala.collection.immutable.List.foreach(List.scala:318)

at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)

at scala.collection.AbstractTraversable.map(Traversable.scala:105)

at geomesa.core.index.IndexEncoder.encode(IndexSchema.scala:244)

at geomesa.core.index.IndexSchema.encode(IndexSchema.scala:91)

at geomesa.core.data.AccumuloFeatureWriter.writeToAccumulo(AccumuloFeatureWriter.scala:103)

at geomesa.core.data.AppendAccumuloFeatureWriter.write(AccumuloFeatureWriter.scala:128)

at org.geotools.data.AbstractFeatureStore.addFeatures(AbstractFeatureStore.java:324)

at geomesa.core.data.AccumuloFeatureStore.addFeatures(AccumuloFeatureStore.scala:53)

at AccumuloTest.ATest.writeFeature(ATest.java:158)

at AccumuloTest.ATest.main(ATest.java:45)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

 

I have used this (*geom:LineString:srid=4326) configuration for geometry field. It only throws this exception in case of LineString, it is working fine with Point and Polygon. Can somebody help me understand what the problem is?

 

Regards,

Adnan

 

 


_______________________________________________
geomesa-users mailing list
geomesa-users@xxxxxxxxxxxxxxxx
http://www.locationtech.org/mailman/listinfo/geomesa-users



_______________________________________________
geomesa-users mailing list
geomesa-users@xxxxxxxxxxxxxxxx
http://www.locationtech.org/mailman/listinfo/geomesa-users



_______________________________________________
geomesa-users mailing list
geomesa-users@xxxxxxxxxxxxxxxx
http://www.locationtech.org/mailman/listinfo/geomesa-users



Back to the top