Re: [JPP-Devel] How to load ESRI shapefiles by code

2010-05-28 Thread Stefan Steiniger
nice!

Do you want write access to the svn?
Then I would need you to register at sourceforge and you send me your 
name there (can be also in personal communication - even in german ;)

stefan

Benjamin Gudehus wrote:
> I should not forget to take a look at DataSourceFileLayerLoader which 
> already provides a similar functionality.
> 
> But it needs to split up in serveral independent methods. i.e. split 
> DataSourceFileLayerLoader.open() into toDataSourceQuery(), 
> toFeatureCollection() and toLayer().
> 
> --Benjamin
> 
> 2010/5/28 Benjamin Gudehus  >
> 
> What I forgot to mention: I've written it in Groovy. My unit tests /
> specifications depend on Groovy and Spock. Once finished I'll
> rewrite/convert the non-test code to Java.
> 
> 2010/5/28 Benjamin Gudehus  >
> 
> I pushed a working draft of DataSourceTools to
> 
> http://bitbucket.org/hastebrot/openjump-groovy-addons/src/653c99258dea/src/org/openjump/groovy/DataSourceTools.groovy.
> 
> Here an outline:
> 
> class DataSourceTools {
>
> static DataSourceQuery toDataSourceQuery(File file, Class
> dataSourceClass,
> CoordinateSystem coordinateSystem)
> static FeatureCollection toFeatureCollection(DataSourceQuery
> dataSourceQuery)
> static DataSource toDataSource(Class dataSourceClass)
>
> }
> 
> class InternalLoadDatasetPlugIn extends AbstractPlugIn {
>
> void initialize(PlugInContext context)
> boolean execute(PlugInContext context)
>
> void setFilepath(File filepath)
>
> // optional -- automatically recognized using file extension
> void setFormat(String format)
>
> // optional -- use CoordinateSystem.UNSPECIFIED
> void setCoordinateSystem()
>
> // optional -- use StandardCategoryNames.WORKING
> void setCategory()
>
> // optional -- use filename without extension.
> void setLayerName()
> }
> 
> 2010/5/28 Larry Becker  >
> 
> Thanks for volunteering to do this Benjamin.  We probably
> need to make a new page on the wiki that documents it called
> something like "how to load layers in a plugin".  A snippet
> of BeanShell would be nice too.  :-]
> 
> regards,
> Larry
> 
> On Fri, May 28, 2010 at 3:26 AM, Benjamin Gudehus
> mailto:hasteb...@googlemail.com>>
> wrote:
> 
> how about not splitting the class (i.e. avoiding to
> break anything), but
> just add the second class for programmatical access?
> Maybe this could
> even go into the core.apitools package.
> 
> 
>  yes, important to make no backward incompatible changes
> to LoadDatasetPlugIn.
> 
> 
> If you feel like creating such a class, I can add it.
> 
> 
> good chance to me to contribute some code ;)
> 
> 
> First step is to extract dataset loading with DataSource
> from LoadDatasetPlugIn into a
> new class called DataSourceTools (or so) in
> org.openjump.core.apitools.
> 
> --Benjamin
> 
> 
> 
> --
> 
> 
> 
> ___
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> 
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
> 
> 
> 
> 
> --
> 
> 
> ___
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> 
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
> 
> 
> 
> 
> 
> 
> 
> --
> 
> 
> 
> 
> 
> ___
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

--


Re: [JPP-Devel] How to load ESRI shapefiles by code

2010-05-28 Thread Sunburned Surveyor
Thanks for everyone that posted or contributed code on this thread.
This is very handy info, and I'll try to post the best excerpts to my
OpenJUMP blog.

The Sunburned Surveyor

On Fri, May 28, 2010 at 9:20 AM, Hernan Arellano  wrote:
> Hi all, in the same way that load a layer by code, I needed load a jpg image
> by code, at the same map.
> I want to share with you too, the code to load an image without a wizard:
>
> ***
> ***
> public boolean execute(PlugInContext context) throws Exception
> {
> LayerManager layerManager = context.getWorkbenchContext().getLayerManager();
> layerManager.setFiringEvents(false);
> File file = new File("c://image.jpg");
> Layer lyr = createLayer(layerManager, file);
> layerManager.setFiringEvents(true);
> Category category =
> TaskUtil.getSelectedCategoryName(context.getWorkbenchContext());
> category.add(0, (Layerable) lyr);
> ReferencedImageFactory imageFactory= new GraphicImageFactory(); //depends
> the image type
> Feature feature = createFeature(imageFactory, file,
> getImageryLayerDataset(lyr));
> lyr.getFeatureCollectionWrapper().add(feature);
> }
>
> private Feature createFeature(ReferencedImageFactory referencedImageFactory,
>             File file, ImageryLayerDataset imageryLayerDataset)
> {
> Feature feature = new BasicFeature(ImageryLayerDataset.getSchema());
> feature.setAttribute(ImageryLayerDataset.ATTR_FILE, file.getPath());
> feature.setAttribute(ImageryLayerDataset.ATTR_FORMAT,
> referencedImageFactory.getTypeName());
> feature.setAttribute(ImageryLayerDataset.ATTR_FACTORY,
> referencedImageFactory.getClass().getName());
> feature.setGeometry(new GeometryFactory().createPoint((Coordinate)null));
> imageryLayerDataset.createImage(feature);
> return feature;
> }
>
> private ImageryLayerDataset
> getImageryLayerDataset(com.vividsolutions.jump.workbench.model.Layer layer)
> {
> ReferencedImageStyle irs =
> (ReferencedImageStyle)layer.getStyle(ReferencedImageStyle.class);
> return irs.getImageryLayerDataset();
> }
> ***
> ***
> Note: in my proyect i have a xml map with layers and images paths, all them
> with the same projection.
>
> Regards!
>
> 
> --
>
>
> ___
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>
>

--

___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] How to load ESRI shapefiles by code

2010-05-28 Thread Hernan Arellano

Hi all, in the same way that load a layer by code, I needed load a jpg image by 
code, at the same map.
I want to share with you too, the code to load an image without a wizard:

***
***
public boolean execute(PlugInContext context) throws Exception
{
LayerManager layerManager = context.getWorkbenchContext().getLayerManager();
layerManager.setFiringEvents(false);
File file = new File("c://image.jpg");
Layer lyr = createLayer(layerManager, file);
layerManager.setFiringEvents(true);
Category category = 
TaskUtil.getSelectedCategoryName(context.getWorkbenchContext());
category.add(0, (Layerable) lyr);
ReferencedImageFactory imageFactory= new GraphicImageFactory(); //depends the 
image type
Feature feature = createFeature(imageFactory, file, 
getImageryLayerDataset(lyr));
lyr.getFeatureCollectionWrapper().add(feature);
}

private Feature createFeature(ReferencedImageFactory referencedImageFactory,
File file, ImageryLayerDataset imageryLayerDataset) 
{
Feature feature = new BasicFeature(ImageryLayerDataset.getSchema());
feature.setAttribute(ImageryLayerDataset.ATTR_FILE, file.getPath());
feature.setAttribute(ImageryLayerDataset.ATTR_FORMAT,
referencedImageFactory.getTypeName());
feature.setAttribute(ImageryLayerDataset.ATTR_FACTORY,
referencedImageFactory.getClass().getName());
feature.setGeometry(new GeometryFactory().createPoint((Coordinate)null));
imageryLayerDataset.createImage(feature);
return feature;
}

private ImageryLayerDataset 
getImageryLayerDataset(com.vividsolutions.jump.workbench.model.Layer layer) 
{
ReferencedImageStyle irs = 
(ReferencedImageStyle)layer.getStyle(ReferencedImageStyle.class);
return irs.getImageryLayerDataset();
}
***
***
Note: in my proyect i have a xml map with layers and images paths, all them 
with the same projection.

Regards!
  
_

--

___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] How to load ESRI shapefiles by code

2010-05-28 Thread Benjamin Gudehus
I should not forget to take a look at DataSourceFileLayerLoader which
already provides a similar functionality.

But it needs to split up in serveral independent methods. i.e. split
DataSourceFileLayerLoader.open() into toDataSourceQuery(),
toFeatureCollection() and toLayer().

--Benjamin

2010/5/28 Benjamin Gudehus 

> What I forgot to mention: I've written it in Groovy. My unit tests /
> specifications depend on Groovy and Spock. Once finished I'll
> rewrite/convert the non-test code to Java.
>
> 2010/5/28 Benjamin Gudehus 
>
> I pushed a working draft of DataSourceTools to
>> http://bitbucket.org/hastebrot/openjump-groovy-addons/src/653c99258dea/src/org/openjump/groovy/DataSourceTools.groovy
>> .
>>
>> Here an outline:
>>
>> class DataSourceTools {
>>
>> static DataSourceQuery toDataSourceQuery(File file, Class
>> dataSourceClass,
>> CoordinateSystem coordinateSystem)
>> static FeatureCollection toFeatureCollection(DataSourceQuery
>> dataSourceQuery)
>> static DataSource toDataSource(Class dataSourceClass)
>>
>> }
>>
>> class InternalLoadDatasetPlugIn extends AbstractPlugIn {
>>
>> void initialize(PlugInContext context)
>> boolean execute(PlugInContext context)
>>
>> void setFilepath(File filepath)
>>
>> // optional -- automatically recognized using file extension
>> void setFormat(String format)
>>
>> // optional -- use CoordinateSystem.UNSPECIFIED
>> void setCoordinateSystem()
>>
>> // optional -- use StandardCategoryNames.WORKING
>> void setCategory()
>>
>> // optional -- use filename without extension.
>> void setLayerName()
>> }
>>
>> 2010/5/28 Larry Becker 
>>
>> Thanks for volunteering to do this Benjamin.  We probably need to make a
>>> new page on the wiki that documents it called something like "how to load
>>> layers in a plugin".  A snippet of BeanShell would be nice too.  :-]
>>>
>>> regards,
>>> Larry
>>>
>>> On Fri, May 28, 2010 at 3:26 AM, Benjamin Gudehus <
>>> hasteb...@googlemail.com> wrote:
>>>
 how about not splitting the class (i.e. avoiding to break anything), but
> just add the second class for programmatical access? Maybe this could
> even go into the core.apitools package.


  yes, important to make no backward incompatible changes to
 LoadDatasetPlugIn.


 If you feel like creating such a class, I can add it.
>

 good chance to me to contribute some code ;)


 First step is to extract dataset loading with DataSource from
 LoadDatasetPlugIn into a
 new class called DataSourceTools (or so) in org.openjump.core.apitools.

 --Benjamin



 --



 ___
 Jump-pilot-devel mailing list
 Jump-pilot-devel@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


>>>
>>>
>>> --
>>>
>>>
>>> ___
>>> Jump-pilot-devel mailing list
>>> Jump-pilot-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>>>
>>>
>>
>
--

___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] How to load ESRI shapefiles by code

2010-05-28 Thread Benjamin Gudehus
What I forgot to mention: I've written it in Groovy. My unit tests /
specifications depend on Groovy and Spock. Once finished I'll
rewrite/convert the non-test code to Java.

2010/5/28 Benjamin Gudehus 

> I pushed a working draft of DataSourceTools to
> http://bitbucket.org/hastebrot/openjump-groovy-addons/src/653c99258dea/src/org/openjump/groovy/DataSourceTools.groovy
> .
>
> Here an outline:
>
> class DataSourceTools {
>
> static DataSourceQuery toDataSourceQuery(File file, Class
> dataSourceClass,
> CoordinateSystem coordinateSystem)
> static FeatureCollection toFeatureCollection(DataSourceQuery
> dataSourceQuery)
> static DataSource toDataSource(Class dataSourceClass)
>
> }
>
> class InternalLoadDatasetPlugIn extends AbstractPlugIn {
>
> void initialize(PlugInContext context)
> boolean execute(PlugInContext context)
>
> void setFilepath(File filepath)
>
> // optional -- automatically recognized using file extension
> void setFormat(String format)
>
> // optional -- use CoordinateSystem.UNSPECIFIED
> void setCoordinateSystem()
>
> // optional -- use StandardCategoryNames.WORKING
> void setCategory()
>
> // optional -- use filename without extension.
> void setLayerName()
> }
>
> 2010/5/28 Larry Becker 
>
> Thanks for volunteering to do this Benjamin.  We probably need to make a
>> new page on the wiki that documents it called something like "how to load
>> layers in a plugin".  A snippet of BeanShell would be nice too.  :-]
>>
>> regards,
>> Larry
>>
>> On Fri, May 28, 2010 at 3:26 AM, Benjamin Gudehus <
>> hasteb...@googlemail.com> wrote:
>>
>>> how about not splitting the class (i.e. avoiding to break anything), but
 just add the second class for programmatical access? Maybe this could
 even go into the core.apitools package.
>>>
>>>
>>>  yes, important to make no backward incompatible changes to
>>> LoadDatasetPlugIn.
>>>
>>>
>>> If you feel like creating such a class, I can add it.

>>>
>>> good chance to me to contribute some code ;)
>>>
>>>
>>> First step is to extract dataset loading with DataSource from
>>> LoadDatasetPlugIn into a
>>> new class called DataSourceTools (or so) in org.openjump.core.apitools.
>>>
>>> --Benjamin
>>>
>>>
>>>
>>> --
>>>
>>>
>>>
>>> ___
>>> Jump-pilot-devel mailing list
>>> Jump-pilot-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>>>
>>>
>>
>>
>> --
>>
>>
>> ___
>> Jump-pilot-devel mailing list
>> Jump-pilot-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>>
>>
>
--

___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] How to load ESRI shapefiles by code

2010-05-28 Thread Benjamin Gudehus
I pushed a working draft of DataSourceTools to
http://bitbucket.org/hastebrot/openjump-groovy-addons/src/653c99258dea/src/org/openjump/groovy/DataSourceTools.groovy
.

Here an outline:

class DataSourceTools {

static DataSourceQuery toDataSourceQuery(File file, Class
dataSourceClass,
CoordinateSystem coordinateSystem)
static FeatureCollection toFeatureCollection(DataSourceQuery
dataSourceQuery)
static DataSource toDataSource(Class dataSourceClass)

}

class InternalLoadDatasetPlugIn extends AbstractPlugIn {

void initialize(PlugInContext context)
boolean execute(PlugInContext context)

void setFilepath(File filepath)

// optional -- automatically recognized using file extension
void setFormat(String format)

// optional -- use CoordinateSystem.UNSPECIFIED
void setCoordinateSystem()

// optional -- use StandardCategoryNames.WORKING
void setCategory()

// optional -- use filename without extension.
void setLayerName()
}

2010/5/28 Larry Becker 

> Thanks for volunteering to do this Benjamin.  We probably need to make a
> new page on the wiki that documents it called something like "how to load
> layers in a plugin".  A snippet of BeanShell would be nice too.  :-]
>
> regards,
> Larry
>
> On Fri, May 28, 2010 at 3:26 AM, Benjamin Gudehus <
> hasteb...@googlemail.com> wrote:
>
>> how about not splitting the class (i.e. avoiding to break anything), but
>>> just add the second class for programmatical access? Maybe this could
>>> even go into the core.apitools package.
>>
>>
>>  yes, important to make no backward incompatible changes to
>> LoadDatasetPlugIn.
>>
>>
>> If you feel like creating such a class, I can add it.
>>>
>>
>> good chance to me to contribute some code ;)
>>
>>
>> First step is to extract dataset loading with DataSource from
>> LoadDatasetPlugIn into a
>> new class called DataSourceTools (or so) in org.openjump.core.apitools.
>>
>> --Benjamin
>>
>>
>>
>> --
>>
>>
>>
>> ___
>> Jump-pilot-devel mailing list
>> Jump-pilot-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>>
>>
>
>
> --
>
>
> ___
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>
>
--

___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] How to load ESRI shapefiles by code

2010-05-28 Thread Larry Becker
Thanks for volunteering to do this Benjamin.  We probably need to make a new
page on the wiki that documents it called something like "how to load layers
in a plugin".  A snippet of BeanShell would be nice too.  :-]

regards,
Larry

On Fri, May 28, 2010 at 3:26 AM, Benjamin Gudehus
wrote:

> how about not splitting the class (i.e. avoiding to break anything), but
>> just add the second class for programmatical access? Maybe this could
>> even go into the core.apitools package.
>
>
>  yes, important to make no backward incompatible changes to
> LoadDatasetPlugIn.
>
>
> If you feel like creating such a class, I can add it.
>>
>
> good chance to me to contribute some code ;)
>
>
> First step is to extract dataset loading with DataSource from
> LoadDatasetPlugIn into a
> new class called DataSourceTools (or so) in org.openjump.core.apitools.
>
> --Benjamin
>
>
>
> --
>
>
> ___
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>
>
--

___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] How to load ESRI shapefiles by code

2010-05-28 Thread Benjamin Gudehus
> how about not splitting the class (i.e. avoiding to break anything), but
> just add the second class for programmatical access? Maybe this could
> even go into the core.apitools package.


 yes, important to make no backward incompatible changes to
LoadDatasetPlugIn.

If you feel like creating such a class, I can add it.
>

good chance to me to contribute some code ;)


First step is to extract dataset loading with DataSource from
LoadDatasetPlugIn into a
new class called DataSourceTools (or so) in org.openjump.core.apitools.

--Benjamin
--

___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] How to load ESRI shapefiles by code

2010-05-27 Thread Hernan Arellano


Thanks for the help guys!   I`ve solved it by the following code:
(maybe there are some things no needed, like options, but it works!!)


DataSource dataSource = 
(DataSource)LangUtil.newInstance(StandardReaderWriterFileDataSource.Shapefile.class);
Map options = new HashMap();
Map properties = new HashMap();
properties.put(DataSource.FILE_KEY, "c://roads.shp");
properties.putAll(options);
dataSource.setProperties(properties);

DataSourceQuery dataSourceQuery = new DataSourceQuery(dataSource, null, 
"roads");
ArrayList exceptions = new ArrayList();
String layerName = dataSourceQuery.toString();

Connection connection = dataSourceQuery.getDataSource().getConnection();
   try 
{
  FeatureCollection dataset = 
dataSourceQuery.getDataSource().installCoordinateSystem(
 connection.executeQuery(dataSourceQuery.getQuery(), exceptions, null),
  
CoordinateSystemRegistry.instance(context.getWorkbenchContext().getBlackboard()));
  if (dataset != null) 
  { 
LayerManager layerManager = 
context.getWorkbenchContext().getLayerManager();
Layer layer = new Layer(layerName, 
layerManager.generateLayerFillColor(), dataset, layerManager);
layerManager.addLayerable("categoryName", (Layerable) layer);
layer.setDataSourceQuery(dataSourceQuery);
layer.setFeatureCollectionModified(false);
layer.setVisible(true);
  }
} finally {
connection.close();
}
**
  
_

--

___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] How to load ESRI shapefiles by code

2010-05-27 Thread Stefan Steiniger
thanks michael,

I add that to the wiki.

Michaël Michaud wrote:
> Hi,
> 
> Don't know if you still want to work inside OpenJUMP  wokbench or not, 
> but here is a very simple example I just picked up from the JTS 
> discussion list :
> 
> String layer = "data/tigerline/2009_us_state/tl_2009_us_state.shp";
> ShapefileReader reader = new ShapefileReader();
> FeatureCollection fc = reader.read(new DriverProperties(layer));
> List fs = fc.getFeatures();
> 
> Is that what you're looking for ?
> 
> Michaël
> 
> Stefan Steiniger a écrit :
>> does it help you too look into this class:
>>
>> com.vividsolutions.jump.workbench.datasource.AbstractLoadDatasetPlugIn
>>
>> I think it is not used anymore...
>>
>> stefan
>>
>> Hernan Arellano wrote:
>>   
>>> Hi all!  i'm working on a project, with OpenJump 1.3.1, that it needs to 
>>> load a set of ESRI Shapefiles from a path to any category of the map.
>>>
>>> I`ve seen the following code to load a shapefile, of the method "open" 
>>> from DataSourceFileLayerLoader class. The problem is that this uses a 
>>> monitor of a dialog that i haven´t, and i tried use this code but i 
>>> couldn`t make the dataset.
>>>
>>> **
>>> Connection connection = dataSourceQuery.getDataSource().getConnection();
>>> try {
>>>   FeatureCollection dataset = 
>>> dataSourceQuery.getDataSource().installCoordinateSystem(
>>>   connection.executeQuery(dataSourceQuery.getQuery(), 
>>> exceptions, monitor),
>>>   
>>> CoordinateSystemRegistry.instance(workbenchContext.getBlackboard()));
>>>   if (dataset != null) {
>>> LayerManager layerManager = workbenchContext.getLayerManager();
>>> Layer layer = new Layer(layerName,
>>>   layerManager.generateLayerFillColor(), dataset, layerManager);
>>> Category category = 
>>> TaskUtil.getSelectedCategoryName(workbenchContext);
>>> layerManager.addLayerable(category.getName(), layer);
>>> layer.setName(layerName);
>>> layer.setDataSourceQuery(dataSourceQuery);
>>> *
>>>
>>> ¿ How can i load a shapefile by code in a simple way without an 
>>> OpenFileWizard ? .
>>>
>>> Thanks in advance!
>>>
>>> 
>>>
>>>
>>> 
>>>
>>> --
>>>
>>>
>>>
>>> 
>>>
>>> ___
>>> Jump-pilot-devel mailing list
>>> Jump-pilot-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>>> 
>> --
>>
>> ___
>> Jump-pilot-devel mailing list
>> Jump-pilot-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>>
>>
>>   
> 
> 
> --
> 
> ___
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
> 
> 

--

___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] How to load ESRI shapefiles by code

2010-05-27 Thread Stefan Steiniger
Hei Benjamin,

how about not splitting the class (i.e. avoiding to break anything), but 
just add the second class for programmatical access? Maybe this could 
even go into the core.apitools package.

If you feel like creating such a class, I can add it.

cheers,
stefan

Benjamin Gudehus wrote:
> Hi!
> 
> If you just want to load shapefiles, you can use ShapefileReader 
> directly to load a shapefile into a FeatureCollection.
> 
> ShapefileReader reader = new ShapefileReader();
> FeatureCollection features = reader.read(new 
> DriverProperties(shapefilePath));
> Layer layer = context.getLayerManager().addLayer("Category Name", "Layer 
> Name", features);
> 
> DataSourceQuery: The monitor parameter is a TaskMonitor and used to 
> report progress and check cancel requests. Connection needs this 
> TaskMonitor, so you need to put the call into the run() method in the 
> (threaded) PlugIn to receive a monitor (public void run(TaskMonitor 
> monitor, PlugInContext context)).
> 
> If you don't want to use the run() / ThreadedPlugIn, you could maybe 
> create a com.vividsolutions.jump.task.DummyTaskMonitor and use it 
> monitor instead? (I didn't test this)
> 
> connection = dataSourceQuery.getDataSource().getConnection()
> connection.executeQuery(query, exceptions, new DummyTaskMonitor())
> 
> --
> 
> BTW: Maybe we should split LoadDatasetPlugIn into two PlugIns (I had 
> this idea a few weeks ago).
> 
> One called LoadDatasetPlugIn without dialog, which loads datasets into 
> the LayerManager.
> 
> LoadDatasetPlugIn datasetPlugIn = new LoadDatasetPlugIn();
> datasetPlugIn.setFilepath("~/shapefiles/world.shp");
> datasetPlugIn.setType("shapefile");
> datasetPlugIn.setCategory("Category Name");
> datasetPlugIn.setLayerName("Layer Name");
> datasetPlugIn.execute();
> 
> Another called LoadDatasetsDialogPlugIn with a dialog, which shows a 
> JFileChooser and uses the LoadDatasetPlugIn.
> 
> With LoadDatasetPlugIn one can programmatically load datasets. 
> LoadDatasetsDialogPlugIn is used in the workbench (File > Open...).
> 
> Greetings from rainy Hanover.
> 
> 
> 2010/5/26 Stefan Steiniger mailto:sst...@geo.uzh.ch>>
> 
> does it help you too look into this class:
> 
> com.vividsolutions.jump.workbench.datasource.AbstractLoadDatasetPlugIn
> 
> I think it is not used anymore...
> 
> stefan
> 
> Hernan Arellano wrote:
>  > Hi all!  i'm working on a project, with OpenJump 1.3.1, that it
> needs to
>  > load a set of ESRI Shapefiles from a path to any category of the map.
>  >
>  > I`ve seen the following code to load a shapefile, of the method
> "open"
>  > from DataSourceFileLayerLoader class. The problem is that this uses a
>  > monitor of a dialog that i haven´t, and i tried use this code but i
>  > couldn`t make the dataset.
>  >
>  > **
>  > Connection connection =
> dataSourceQuery.getDataSource().getConnection();
>  > try {
>  >   FeatureCollection dataset =
>  > dataSourceQuery.getDataSource().installCoordinateSystem(
>  >   connection.executeQuery(dataSourceQuery.getQuery(),
>  > exceptions, monitor),
>  >
>  > CoordinateSystemRegistry.instance(workbenchContext.getBlackboard()));
>  >   if (dataset != null) {
>  > LayerManager layerManager =
> workbenchContext.getLayerManager();
>  > Layer layer = new Layer(layerName,
>  >   layerManager.generateLayerFillColor(), dataset,
> layerManager);
>  > Category category =
>  > TaskUtil.getSelectedCategoryName(workbenchContext);
>  > layerManager.addLayerable(category.getName(), layer);
>  > layer.setName(layerName);
>  > layer.setDataSourceQuery(dataSourceQuery);
>  > *
>  >
>  > ¿ How can i load a shapefile by code in a simple way without an
>  > OpenFileWizard ? .
>  >
>  > Thanks in advance!
>  >
>  >
> 
>  >
>  >
>  >
> 
>  >
>  >
> 
> --
>  >
>  >
>  >
>  >
> 
>  >
>  > ___
>  > Jump-pilot-devel mailing list
>  > Jump-pilot-devel@lists.sourceforge.net
> 
>  > https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
> 
> 
> --
> 
> ___
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> 
> https://lists.sourceforge.n

Re: [JPP-Devel] How to load ESRI shapefiles by code

2010-05-27 Thread Michaël Michaud
Hi,

Don't know if you still want to work inside OpenJUMP  wokbench or not, 
but here is a very simple example I just picked up from the JTS 
discussion list :

String layer = "data/tigerline/2009_us_state/tl_2009_us_state.shp";
ShapefileReader reader = new ShapefileReader();
FeatureCollection fc = reader.read(new DriverProperties(layer));
List fs = fc.getFeatures();

Is that what you're looking for ?

Michaël

Stefan Steiniger a écrit :
> does it help you too look into this class:
>
> com.vividsolutions.jump.workbench.datasource.AbstractLoadDatasetPlugIn
>
> I think it is not used anymore...
>
> stefan
>
> Hernan Arellano wrote:
>   
>> Hi all!  i'm working on a project, with OpenJump 1.3.1, that it needs to 
>> load a set of ESRI Shapefiles from a path to any category of the map.
>>
>> I`ve seen the following code to load a shapefile, of the method "open" 
>> from DataSourceFileLayerLoader class. The problem is that this uses a 
>> monitor of a dialog that i haven´t, and i tried use this code but i 
>> couldn`t make the dataset.
>>
>> **
>> Connection connection = dataSourceQuery.getDataSource().getConnection();
>> try {
>>   FeatureCollection dataset = 
>> dataSourceQuery.getDataSource().installCoordinateSystem(
>>   connection.executeQuery(dataSourceQuery.getQuery(), 
>> exceptions, monitor),
>>   
>> CoordinateSystemRegistry.instance(workbenchContext.getBlackboard()));
>>   if (dataset != null) {
>> LayerManager layerManager = workbenchContext.getLayerManager();
>> Layer layer = new Layer(layerName,
>>   layerManager.generateLayerFillColor(), dataset, layerManager);
>> Category category = 
>> TaskUtil.getSelectedCategoryName(workbenchContext);
>> layerManager.addLayerable(category.getName(), layer);
>> layer.setName(layerName);
>> layer.setDataSourceQuery(dataSourceQuery);
>> *
>>
>> ¿ How can i load a shapefile by code in a simple way without an 
>> OpenFileWizard ? .
>>
>> Thanks in advance!
>>
>> 
>>
>>
>> 
>>
>> --
>>
>>
>>
>> 
>>
>> ___
>> Jump-pilot-devel mailing list
>> Jump-pilot-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>> 
>
> --
>
> ___
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>
>
>   


--

___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] How to load ESRI shapefiles by code

2010-05-27 Thread Benjamin Gudehus
Hi!

If you just want to load shapefiles, you can use ShapefileReader directly to
load a shapefile into a FeatureCollection.

ShapefileReader reader = new ShapefileReader();
FeatureCollection features = reader.read(new
DriverProperties(shapefilePath));
Layer layer = context.getLayerManager().addLayer("Category Name", "Layer
Name", features);

DataSourceQuery: The monitor parameter is a TaskMonitor and used to report
progress and check cancel requests. Connection needs this TaskMonitor, so
you need to put the call into the run() method in the (threaded) PlugIn to
receive a monitor (public void run(TaskMonitor monitor, PlugInContext
context)).

If you don't want to use the run() / ThreadedPlugIn, you could maybe create
a com.vividsolutions.jump.task.DummyTaskMonitor and use it monitor instead?
(I didn't test this)

connection = dataSourceQuery.getDataSource().getConnection()
connection.executeQuery(query, exceptions, new DummyTaskMonitor())

--

BTW: Maybe we should split LoadDatasetPlugIn into two PlugIns (I had this
idea a few weeks ago).

One called LoadDatasetPlugIn without dialog, which loads datasets into the
LayerManager.

LoadDatasetPlugIn datasetPlugIn = new LoadDatasetPlugIn();
datasetPlugIn.setFilepath("~/shapefiles/world.shp");
datasetPlugIn.setType("shapefile");
datasetPlugIn.setCategory("Category Name");
datasetPlugIn.setLayerName("Layer Name");
datasetPlugIn.execute();

Another called LoadDatasetsDialogPlugIn with a dialog, which shows a
JFileChooser and uses the LoadDatasetPlugIn.

With LoadDatasetPlugIn one can programmatically load datasets.
LoadDatasetsDialogPlugIn is used in the workbench (File > Open...).

Greetings from rainy Hanover.


2010/5/26 Stefan Steiniger 

> does it help you too look into this class:
>
> com.vividsolutions.jump.workbench.datasource.AbstractLoadDatasetPlugIn
>
> I think it is not used anymore...
>
> stefan
>
> Hernan Arellano wrote:
> > Hi all!  i'm working on a project, with OpenJump 1.3.1, that it needs to
> > load a set of ESRI Shapefiles from a path to any category of the map.
> >
> > I`ve seen the following code to load a shapefile, of the method "open"
> > from DataSourceFileLayerLoader class. The problem is that this uses a
> > monitor of a dialog that i haven´t, and i tried use this code but i
> > couldn`t make the dataset.
> >
> > **
> > Connection connection = dataSourceQuery.getDataSource().getConnection();
> > try {
> >   FeatureCollection dataset =
> > dataSourceQuery.getDataSource().installCoordinateSystem(
> >   connection.executeQuery(dataSourceQuery.getQuery(),
> > exceptions, monitor),
> >
> > CoordinateSystemRegistry.instance(workbenchContext.getBlackboard()));
> >   if (dataset != null) {
> > LayerManager layerManager = workbenchContext.getLayerManager();
> > Layer layer = new Layer(layerName,
> >   layerManager.generateLayerFillColor(), dataset, layerManager);
> > Category category =
> > TaskUtil.getSelectedCategoryName(workbenchContext);
> > layerManager.addLayerable(category.getName(), layer);
> > layer.setName(layerName);
> > layer.setDataSourceQuery(dataSourceQuery);
> > *
> >
> > ¿ How can i load a shapefile by code in a simple way without an
> > OpenFileWizard ? .
> >
> > Thanks in advance!
> >
> > 
> >
> >
> > 
> >
> >
> --
> >
> >
> >
> > 
> >
> > ___
> > Jump-pilot-devel mailing list
> > Jump-pilot-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>
>
> --
>
> ___
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>
--

___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] How to load ESRI shapefiles by code

2010-05-26 Thread Stefan Steiniger
does it help you too look into this class:

com.vividsolutions.jump.workbench.datasource.AbstractLoadDatasetPlugIn

I think it is not used anymore...

stefan

Hernan Arellano wrote:
> Hi all!  i'm working on a project, with OpenJump 1.3.1, that it needs to 
> load a set of ESRI Shapefiles from a path to any category of the map.
> 
> I`ve seen the following code to load a shapefile, of the method "open" 
> from DataSourceFileLayerLoader class. The problem is that this uses a 
> monitor of a dialog that i haven´t, and i tried use this code but i 
> couldn`t make the dataset.
> 
> **
> Connection connection = dataSourceQuery.getDataSource().getConnection();
> try {
>   FeatureCollection dataset = 
> dataSourceQuery.getDataSource().installCoordinateSystem(
>   connection.executeQuery(dataSourceQuery.getQuery(), 
> exceptions, monitor),
>   
> CoordinateSystemRegistry.instance(workbenchContext.getBlackboard()));
>   if (dataset != null) {
> LayerManager layerManager = workbenchContext.getLayerManager();
> Layer layer = new Layer(layerName,
>   layerManager.generateLayerFillColor(), dataset, layerManager);
> Category category = 
> TaskUtil.getSelectedCategoryName(workbenchContext);
> layerManager.addLayerable(category.getName(), layer);
> layer.setName(layerName);
> layer.setDataSourceQuery(dataSourceQuery);
> *
> 
> ¿ How can i load a shapefile by code in a simple way without an 
> OpenFileWizard ? .
> 
> Thanks in advance!
> 
> 
> 
> 
> 
> 
> --
> 
> 
> 
> 
> 
> ___
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

--

___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel