From: Pedro M. <p.m...@gm...> - 2011-04-28 09:50:05
|
I think I making some progress. Here are some of my conclusions: - Instead of implementing a Context for each type of Agent that one need to visualize and to add some behaviour, one should have only a main Context with one Geography Projection. - All the features from the shapefiles that one needs to manipulate should be mapped to Agents and added to the geography projection in the main context (see the example below). - If one is dealing with a fair amount of features (let's say 50000 features where the geometry type is irrelevant) that are mapped to Agents, one should expect a loading time of several minutes. Please correct me if I said something that's not right. Best regards, Pedro Mendes *(the example)* import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import org.geotools.data.shapefile.ShapefileDataStore; import org.geotools.feature.Feature; import org.geotools.feature.FeatureCollection; import org.geotools.feature.FeatureIterator; import repast.simphony.context.DefaultContext; import repast.simphony.context.space.gis.GeographyFactoryFinder; import repast.simphony.space.gis.Geography; import repast.simphony.space.gis.GeographyParameters; import repast.simphony.space.gis.ShapefileLoader; /** * @author pmendes * */ public class TopologyContext extends DefaultContext<Object>{ public TopologyContext() { super("TopologyContext"); GeographyParameters<Object> params = new GeographyParameters<Object>(); Geography<Object> geography = GeographyFactoryFinder.createGeographyFactory(null).createGeography("TopologyGeography", this, params); URL fileURL; ShapefileDataStore store; FeatureCollection collection; try { fileURL = new File("misc/shapefile/exchanges.shp").toURI().toURL(); store = new ShapefileDataStore(fileURL); collection = store.getFeatureSource().getFeatures(); ShapefileLoader<ExchangeAgent> eloader = new ShapefileLoader<ExchangeAgent>(ExchangeAgent.class, fileURL, geography, this); FeatureIterator fIterator = collection.features(); System.out.println("Preparing to load a set of Exchange Agents..."); while (eloader.hasNext()) { Feature feature = fIterator.next(); ExchangeAgent agent = new ExchangeAgent(extractFeatureId(feature), (String)feature.getAttribute("label")); eloader.next(agent); } fIterator.close(); System.out.println(collection.size() + " Exchange Agents loaded!"); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { fileURL = new File("misc/shapefile/routes-smaller.shp").toURI().toURL(); store = new ShapefileDataStore(fileURL); collection = store.getFeatureSource().getFeatures(); ShapefileLoader<RouteAgent> rloader = new ShapefileLoader<RouteAgent>(RouteAgent.class, fileURL, geography, this); FeatureIterator fIterator = collection.features(); System.out.println("Preparing to load a set of Route Agents... "); while (rloader.hasNext()) { Feature feature = fIterator.next(); RouteAgent agent = new RouteAgent( extractFeatureId(feature), (String) feature.getAttribute("entity"), (String) feature.getAttribute("network"), (String) feature.getAttribute("instalation"), (Double) feature.getAttribute("length_m")); rloader.next(agent); } fIterator.close(); System.out.println(collection.size() + " Route Agents loaded!"); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } /** * @param feature * @return the numeric part of the feature id */ protected static int extractFeatureId(Feature feature){ return Integer.parseInt(feature.getID().substring(feature.getID().indexOf(".") + 1)); } } On Wed, Apr 27, 2011 at 6:08 PM, Pedro Mendes <p.m...@gm...>wrote: > > Hi, > > > S. Markisic wrote: > > > > In my project i need to visualize these actually "static" layers without > > this work around, becouse i have to change the behaviour and > visualisation > > dynamically. > > > > Did you achieve this? I'm having the same problem. The several contexts, > geographic projections and the agents are been created but I can only see > the shapefile's data when I put it in static layers... > > My agents are been dynamically mapped from shapefile's features. Here's an > example: > > <!-- CODE --> > public RouteContext() { > super("RouteContext"); > > GeographyParameters<RouteAgent> params = new > GeographyParameters<RouteAgent>(); > // params.setCrs("EPSG:3763"); > Geography<RouteAgent> geography = > > GeographyFactoryFinder.createGeographyFactory(null).createGeography("RouteGeography", > this, params); > File file = new File("misc/shapefile/routes.shp"); > ShapefileLoader<RouteAgent> loader; > > try { > URL fileURL = file.toURI().toURL(); > ShapefileDataStore store = new > ShapefileDataStore(fileURL); > FeatureCollection collection = > store.getFeatureSource().getFeatures(); > loader = new > ShapefileLoader<RouteAgent>(RouteAgent.class, fileURL, > geography, this); > FeatureIterator fIterator = collection.features(); > > // logger.debug("Preparing to load > "+collection.size()+" Route > Agents..."); > System.out.println("Preparing to load > "+collection.size()+" Route > Agents..."); > > while (loader.hasNext()) { > Feature feature = fIterator.next(); > RouteAgent agent = new RouteAgent( > > TopologyContext.extractFeatureId(feature), > (String) > feature.getAttribute("entity"), > (String) > feature.getAttribute("network"), > (String) > feature.getAttribute("instalation"), > > (Double)feature.getAttribute("length_m")); > loader.next(agent); > //logger.debug(agent.toString()); > //System.out.println(agent.toString()); > } > > } catch (MalformedURLException e) { > //logger.error(e, e); > e.printStackTrace(); > } catch (IOException e) { > //logger.error(e, e); > e.printStackTrace(); > } > } > <!-- CODE --> > > -- > View this message in context: > http://old.nabble.com/GIS-Display---Shapefiles-and-Subcontexts-tp30849648p31489286.html > Sent from the repast-interest mailing list archive at Nabble.com. > > > > ------------------------------------------------------------------------------ > WhatsUp Gold - Download Free Network Management Software > The most intuitive, comprehensive, and cost-effective network > management toolset available today. Delivers lowest initial > acquisition cost and overall TCO of any competing solution. > http://p.sf.net/sfu/whatsupgold-sd > _______________________________________________ > Repast-interest mailing list > Rep...@li... > https://lists.sourceforge.net/lists/listinfo/repast-interest > |