Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [udig-devel] Fwd: Re: where conditions while displaying postgis table

Hey,

I'm trying to add some objects from postgis database to uDig as layer. I would just work once, the second time an exception "type cannot by changed" would arise (caused by the same feature name). So I just tried to extract the feature and just change the name. Unfortunately, NullPointerException is thrown. 
 
I'm basically using SQL to filter my Machine collection. I don't know if there is a different solution being able to add several layers showing certain Machine objects from Database. Any help is appreciated!

Here is my code: 

SimpleFeatureType simpleFeatureType = null;
{
	SimpleFeatureTypeBuilder sftb = new SimpleFeatureTypeBuilder();

	DataStore dataStore = connect(new PostgisNGDataStoreFactory());
	FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = dataStore
			.getFeatureSource("machine");
	dataStore.dispose();
	sftb.init(featureSource.getSchema());
	sftb.setName(nameText.getText()); // THE NEW NAME
	sftb.setCRS(DefaultGeographicCRS.WGS84);
	simpleFeatureType = sftb.buildFeatureType();
}

List<Machine> ms; // Lookup of machines from DB 

int index = 0;
FeatureCollection<SimpleFeatureType, SimpleFeature> fCollection = FeatureCollections
	.newCollection();
for (Machine m : ms) {
	fCollection.add(SimpleFeatureBuilder.build(
		simpleFeatureType, new Object[] { m },
		("name" + index++)));
}

IGeoResource resource = CatalogPlugin.getDefault()
	.getLocalCatalog()
	.createTemporaryResource(simpleFeatureType);

resource.resolve(FeatureStore.class, new NullProgressMonitor())
	.addFeatures(fCollection);

ApplicationGIS.addLayersToMap(ApplicationGIS.getActiveMap(),
	Collections.singletonList(resource), ApplicationGIS
	.getActiveMap().getElements().size());
	
Following exception is caused:

net.refractions.udig.project.render.RenderException: Exception(s) occured during rendering: null
	at net.refractions.udig.render.internal.feature.basic.BasicFeatureRenderer.render(BasicFeatureRenderer.java:355)
	at net.refractions.udig.render.internal.feature.basic.BasicFeatureRenderer.render(BasicFeatureRenderer.java:224)
	at net.refractions.udig.project.internal.render.impl.RenderJob.startRendering(RenderJob.java:108)
	at net.refractions.udig.project.internal.render.impl.RenderJob.run(RenderJob.java:213)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.lang.NullPointerException
	at org.geotools.data.memory.MemoryDataStore.getBounds(MemoryDataStore.java:600)
	at org.geotools.data.AbstractFeatureSource.getBounds(AbstractFeatureSource.java:308)
	at org.geotools.data.AbstractFeatureSource.getBounds(AbstractFeatureSource.java:276)
	at net.refractions.udig.catalog.memory.internal.MemoryGeoResourceImpl$ScratchResourceInfo.getBounds(MemoryGeoResourceImpl.java:155)
	at net.refractions.udig.project.internal.impl.GeoResourceInfoInterceptor$Wrapper.getBounds(GeoResourceInfoInterceptor.java:68)
	at net.refractions.udig.project.internal.impl.LayerImpl.obtainBoundsFromResources(LayerImpl.java:2014)
	at net.refractions.udig.project.internal.impl.LayerImpl.getBounds(LayerImpl.java:1985)
	at net.refractions.udig.render.internal.feature.basic.BasicFeatureRenderer.validateBounds(BasicFeatureRenderer.java:438)
	at net.refractions.udig.render.internal.feature.basic.BasicFeatureRenderer.render(BasicFeatureRenderer.java:253)
	... 4 more
net.refractions.udig.project.render.RenderException: Exception(s) occured during rendering: null
	at net.refractions.udig.render.internal.feature.basic.BasicFeatureRenderer.render(BasicFeatureRenderer.java:355)
	at net.refractions.udig.render.internal.feature.basic.BasicFeatureRenderer.render(BasicFeatureRenderer.java:224)
	at net.refractions.udig.project.internal.render.impl.RenderJob.startRendering(RenderJob.java:108)
	at net.refractions.udig.project.internal.render.impl.RenderJob.run(RenderJob.java:213)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.lang.NullPointerException
	at org.geotools.data.memory.MemoryDataStore.getBounds(MemoryDataStore.java:600)
	at org.geotools.data.AbstractFeatureSource.getBounds(AbstractFeatureSource.java:308)
	at org.geotools.data.AbstractFeatureSource.getBounds(AbstractFeatureSource.java:276)
	at net.refractions.udig.catalog.memory.internal.MemoryGeoResourceImpl$ScratchResourceInfo.getBounds(MemoryGeoResourceImpl.java:155)
	at net.refractions.udig.project.internal.impl.GeoResourceInfoInterceptor$Wrapper.getBounds(GeoResourceInfoInterceptor.java:68)
	at net.refractions.udig.project.internal.impl.LayerImpl.obtainBoundsFromResources(LayerImpl.java:2014)
	at net.refractions.udig.project.internal.impl.LayerImpl.getBounds(LayerImpl.java:1985)
	at net.refractions.udig.render.internal.feature.basic.BasicFeatureRenderer.validateBounds(BasicFeatureRenderer.java:438)
	at net.refractions.udig.render.internal.feature.basic.BasicFeatureRenderer.render(BasicFeatureRenderer.java:253)
	... 4 more

Thanks in advance!

Konstantin

-------- Original-Nachricht --------
> Datum: Tue, 6 Jul 2010 09:27:56 +1000
> Von: Jody Garnett <jody.garnett@xxxxxxxxx>
> An: User-friendly Desktop Internet GIS <udig-devel@xxxxxxxxxxxxxxxxxxxxx>
> Betreff: Re: [udig-devel] Fwd: Re: where conditions while displaying postgis	table

> The layer; once created has a label or title you can just change (the same
> way a user can rename a layer).
> 
> The default layer name comes from the GeoResource.getInfo( null
> ).getTitle();
> 
> Jody
> 
> On 06/07/2010, at 5:36 AM, konfri@xxxxxx wrote:
> 
> > Hey Jody,
> > 
> > the "java.lang.ClassNotFoundException:
> com.vividsolutions.jts.geom.GeometryFactory" was caused by some strange dependency issues. I got this
> working. 
> > 
> > You suggested as solution for my question feature types. It works, but I
> was wondering if could set the visual layer name in uDig? Unfortunately,
> it is always "machine" ... 
> > 
> > DataStore dataStore = connect(new PostgisNGDataStoreFactory());
> > FeatureSource<SimpleFeatureType, SimpleFeature> featureSource =
> dataStore.getFeatureSource("machine");
> > FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection =
> featureSource.getFeatures();
> > 
> > List<Machine> ms; // list of machines from DB
> > 
> > int index = 0;
> > for (MachineCharging m : ms) { 
> featureCollection.add(SimpleFeatureBuilder.build(featureSource.getSchema(),new Object[] { m },("name" + index++)));
> > }
> > 
> > IGeoResource resource =      
> CatalogPlugin.getDefault().getLocalCatalog().createTemporaryResource(featureSource.getSchema());
> > resource.resolve(FeatureStore.class, new
> NullProgressMonitor()).addFeatures(featureCollection);
> > 
> >
> ApplicationGIS.addLayersToMap(ApplicationGIS.getActiveMap(),Collections.singletonList(resource),
> ApplicationGIS.getActiveMap().getElements().size());
> > 
> > Thanks again for your help :)
> > 
> > Konstantin
> > 
> > 
> >> 
> >> 
> >> -------- Original Message --------
> >> Subject: 	Re: [udig-devel] where conditions while displaying postgis
> table
> >> Date: 	Sun, 27 Jun 2010 10:11:54 +1000
> >> From: 	Jody Garnett <jody.garnett@xxxxxxxxx>
> >> Reply-To: 	User-friendly Desktop Internet GIS 
> >> <udig-devel@xxxxxxxxxxxxxxxxxxxxx>
> >> To: 	User-friendly Desktop Internet GIS
> <udig-devel@xxxxxxxxxxxxxxxxxxxxx>
> >> 
> >> 
> >> 
> >> Wow that is strange; the only thing I can think of is that OSGi is
> letting you have two copies of jts around? And it is having trouble casting
> instances made under one classloader to instances made with the other?
> >> 
> >> In eclipse could you check your properties>  java build path and see
> what is happening?
> >> 
> >> As you say this is really odd.
> >> 
> >> Jody
> >> 
> >> 
> >> On 27/06/2010, at 5:43 AM,konfri@xxxxxx  wrote:
> >> 
> >>> Hey Jody,
> >>> 
> >>> thanks for your reply. I tried your first suggestion and created
> feature type. Unfortunately an exception is thrown:
> >>> 
> >>> net.refractions.udig.project.render.RenderException: Exception(s)
> occured during rendering: com.vividsolutions.jts.geom.Point cannot be cast to
> com.vividsolutions.jts.geom.Geometry
> >>>    at
> net.refractions.udig.render.internal.feature.basic.BasicFeatureRenderer.render(BasicFeatureRenderer.java:355)
> >>>    at
> net.refractions.udig.render.internal.feature.basic.BasicFeatureRenderer.render(BasicFeatureRenderer.java:224)
> >>>    at
> net.refractions.udig.project.internal.render.impl.RenderJob.startRendering(RenderJob.java:108)
> >>>    at
> net.refractions.udig.project.internal.render.impl.RenderJob.run(RenderJob.java:213)
> >>>    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
> >>> Caused by: java.lang.ClassCastException:
> com.vividsolutions.jts.geom.Point cannot be cast to com.vividsolutions.jts.geom.Geometry
> >>>    at
> org.geotools.data.memory.MemoryDataStore.getBounds(MemoryDataStore.java:600)
> >>>    at
> org.geotools.data.AbstractFeatureSource.getBounds(AbstractFeatureSource.java:308)
> >>>    at
> org.geotools.data.AbstractFeatureSource.getBounds(AbstractFeatureSource.java:276)
> >>>    at
> net.refractions.udig.catalog.memory.internal.MemoryGeoResourceImpl$ScratchResourceInfo.getBounds(MemoryGeoResourceImpl.java:155)
> >>>    at
> net.refractions.udig.project.internal.impl.GeoResourceInfoInterceptor$Wrapper.getBounds(GeoResourceInfoInterceptor.java:68)
> >>>    at
> net.refractions.udig.project.internal.impl.LayerImpl.obtainBoundsFromResources(LayerImpl.java:2014)
> >>>    at
> net.refractions.udig.project.internal.impl.LayerImpl.getBounds(LayerImpl.java:1985)
> >>>    at
> net.refractions.udig.render.internal.feature.basic.BasicFeatureRenderer.validateBounds(BasicFeatureRenderer.java:438)
> >>>    at
> net.refractions.udig.render.internal.feature.basic.BasicFeatureRenderer.render(BasicFeatureRenderer.java:253)
> >>>    ... 4 more
> >>> 
> >>> The part of my source code:
> >>> 
> >>> FeatureCollection<SimpleFeatureType, SimpleFeature>  collection =
> FeatureCollections
> >>>        .newCollection();
> >>> List<House>  mcs = Util.getHouses();
> >>> 
> >>> SimpleFeatureType sft = null;
> >>> {
> >>>    SimpleFeatureType temp = DataUtilities.createType("Houses",
> "name:String,position:Point");
> >>>    sft = DataUtilities.createSubType(temp, null,
> DefaultGeographicCRS.WGS84);
> >>> }
> >>> 
> >>> int index = 0;
> >>> for (House mc : mcs) {
> >>>    collection.add(SimpleFeatureBuilder.build(sft,new Object[] {
> mc.getName(),mc.getPos() },"House" + index++));
> >>> }
> >>> 
> >>> IGeoResource resource =
> CatalogPlugin.getDefault().getLocalCatalog().createTemporaryResource(sft);
> >>> resource.resolve(FeatureStore.class, new
> NullProgressMonitor()).addFeatures(collection);
> >>> 
> >>> ApplicationGIS.addLayersToMap(ApplicationGIS
> >>>        .getActiveMap(), Collections
> >>>        .singletonList(resource), ApplicationGIS
> >>>        .getActiveMap().getElements().size());
> >>> 
> >>> 
> >>> It's a strange exceptions, since I've used a working example being
> able to visualize some sample points.
> >>> 
> >>> collection.add(SimpleFeatureBuilder.build(sft, new Object[] {
> wkt.read("POINT(4 4)"), "XX2" }, "name2"));
> >>> 
> >>> This line would produce a working layer that could be visualized by
> uDig. My House object already provides the position property as a point.
> >>> 
> >>> 
> >>> In addition, I would like to know if the is a more straightforward way
> in creating feature types instead of producing strings with name and type?
> >>> 
> >>> Best regards,
> >>> 
> >>> Konstantin
> >>> 
> >>> 
> >>> On 06/22/2010 01:50 AM, Jody Garnett wrote:
> >>>> I am afraid the filter standard we use for interacting with
> shapefiles, postgis and web feature servers is focused just on a single where
> statement and does not offer joins.
> >>>> 
> >>>> So I will have to ask you to create a view in your database for this
> purpose.
> >>>> 
> >>>> There are two developments occurring in GeoTools that should help:
> >>>> - app schema work allowing you to define a feature type and provide a
> mapping to the various tables that form its content
> >>>> - andrea is looking at allowing sql based queries which would
> hopefully be similar to defining your own view
> >>>> 
> >>>> I have also personally created a work around (a function that does a
> "lookup" in another table file; I ended up loading the other file into
> memory to make this happen and cannot really recommend it).
> >>>> 
> >>>> Jody
> >>>> 
> >>>> On 22/06/2010, at 2:19 AM,konfri@xxxxxx  wrote:
> >>>> 
> >>>>> Hey,
> >>>>> 
> >>>>> I'm having a postgis table with several columns storing the position
> and some meta information like the time. Now, I would like to use the meta
> information (can be distributed over several tables) and visualizing only
> certain rows.
> >>>>> 
> >>>>> At present, I'm using the catalog to display the entire postgis
> table. Is there a way of adding additional where-conditions?
> >>>>> 
> >>>>> Thanks,
> >>>>> 
> >>>>> Kon
> >>>>> 
> >>>>> -- 
> >>>>> GMX DSL: Internet-, Telefon- und Handy-Flat ab 19,99 EUR/mtl.
> >>>>> Bis zu 150 EUR Startguthaben
> inklusive!http://portal.gmx.net/de/go/dsl
> >>>>> _______________________________________________
> >>>>> User-friendly Desktop Internet GIS (uDig)
> >>>>> http://udig.refractions.net
> >>>>> http://lists.refractions.net/mailman/listinfo/udig-devel
> >>>> 
> >>>> _______________________________________________
> >>>> User-friendly Desktop Internet GIS (uDig)
> >>>> http://udig.refractions.net
> >>>> http://lists.refractions.net/mailman/listinfo/udig-devel
> >>>> 
> >>> 
> >>> 
> >>> -- 
> >>> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> >>> Jetzt freischalten unterhttp://portal.gmx.net/de/go/maxdome01
> >>> _______________________________________________
> >>> User-friendly Desktop Internet GIS (uDig)
> >>> http://udig.refractions.net
> >>> http://lists.refractions.net/mailman/listinfo/udig-devel
> >> 
> >> _______________________________________________
> >> User-friendly Desktop Internet GIS (uDig)
> >> http://udig.refractions.net
> >> http://lists.refractions.net/mailman/listinfo/udig-devel
> >> 
> > 
> > 
> > -- 
> > GMX DSL: Internet-, Telefon- und Handy-Flat ab 19,99 EUR/mtl.  
> > Bis zu 150 EUR Startguthaben inklusive! http://portal.gmx.net/de/go/dsl
> > _______________________________________________
> > User-friendly Desktop Internet GIS (uDig)
> > http://udig.refractions.net
> > http://lists.refractions.net/mailman/listinfo/udig-devel
> 
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01


Back to the top