Hi Jesse!
Your suggestion of adding the line:
CatalogPlugin.getDefault().getLocalCatalog().add(service);
Did not fix the problem.
I still get the Layer with and x and the message: 'Connection to
Resource Failed'
In the console I have:
20-Mar-2006 13:44:15
org.geotools.data.shapefile.ShapefileDataStore openPrjReader
WARNING: projection (.prj) for shapefile not available
20-Mar-2006 13:44:15
org.geotools.data.shapefile.ShapefileDataStore openPrjReader
WARNING: projection (.prj) for shapefile not available
20-Mar-2006 13:44:15
org.geotools.data.shapefile.indexed.IndexedShapefileDataStore
buildQuadTree
INFO: Creating spatial index for
/Eclipse/Ecosensus/Shapefiles/border-otter.shp
Not sure if that helps you diagnose my problem?
I am not sure what a .prj file is, or why it has not got one.
Michelle
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
M.S.Bachler
Sent: 16 March 2006 12:59
To: User-friendly Desktop Internet GIS
Subject: RE: [udig-devel] Shapefiles
Hi!
I know can get the x,y which is great. Thanks.
I have had a first attempt at creating a shapefile and adding a new
layer connecting to the shape file, for the first time you drop a
specific icon on a map (subsequent times you add it to an existing layer
- which is the next step).
I have pieced together code from various emails but still think I have
not really got a complete picture of what I am doing. The code I have,
creates a shape file (I can see the files are there), it also adds a
layer to the map (I can see the layer in the list), but it has an error
- 'Connection to Resource Failed'.
I am also not sure if the Point code is right?
Here is my code: Any thoughts anyone about what I am doing wrong? (or
how I could simplify it?)
try {
IndexedShapefileDataStoreFactory fac = new
IndexedShapefileDataStoreFactory();
File file2 = new
File("Ecosensus"+EcosensusPlugin.sFS+"Shapefiles"+EcosensusPlugin.sFS+sF
ileName+".shp");
String sShapeFile = file2.getAbsolutePath();
ShapefileDataStore ds = (ShapefileDataStore)
fac.createDataStore(new URL("file://"+sShapeFile));
try {
AttributeType geomAttr =
AttributeTypeFactory.newAttributeType("the_geom", Point.class);
FeatureType featureType =
FeatureTypeBuilder.newFeatureType(new AttributeType[] {geomAttr},
"icon");
GeometryFactory geomFactory = new GeometryFactory();
Coordinate coord = new Coordinate(event.x, event.y);
Point point = geomFactory.createPoint(coord);
Feature theIcon = featureType.create(new Object[]
{point}, "myicon");
ds.createSchema( featureType );
List<IService> services =
CatalogPlugin.getDefault().getServiceFactory().acquire(new
URL("file://"+sShapeFile));
IService service = services.get(0);
List resources = service.members(monitor);
IGeoResource resource = (IGeoResource)resources.get(0);
System.out.println("resource type =
"+resource.getClass().getName());
Layer newLayer = factory.createLayer(resource);
newLayer.setName(sFileName);
map.sendCommandASync( (new AddLayerCommand(newLayer)) );
DrawCommandFactory factory2 =
DrawCommandFactory.getInstance();
DrawFeatureCommand cmd =
factory2.createDrawFeatureCommand(theIcon, crs);
map.sendCommandASync(cmd);
} catch (IllegalAttributeException e) {
System.out.println("IllegalAttributeException");
e.printStackTrace();
} catch(SchemaException se) {
System.out.println("SchemaException");
se.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
Michelle
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jesse
Eichar
Sent: 14 March 2006 20:30
To: User-friendly Desktop Internet GIS
Subject: Re: [udig-devel] Shapefiles
Here's the interface (I added some comments today as well :P):
/**
*
* Defines the behaviour when a drag and drop event occurs. The
extension declaration combined with the accepts method
* determines whether the Action will be ran for a given drag/drop event.
*
* @author jdeolive
* @since 1.0.0
*/
public abstract class IDropAction {
public static final String XPID =
"net.refractions.udig.ui.dropAction"; //$NON-NLS-1$
/** the extension info **/
IConfigurationElement element;
private Object destination;
private Object data;
private DropTargetEvent event;
private int location;
/**
* Returns the Configuration element that definates the action
in the extension declaration.
*
* @return the Configuration element that definates the action
in the extension declaration.
*/
public IConfigurationElement getElement() {
return element;
}
/**
* Returns the name of the action.
*
* @return Returns the name of the action.
*/
public String getName() {
if (element == null)
return ""; //$NON-NLS-1$
return element.getAttribute("name"); //$NON-NLS-1$
}
/**
* Called if the action seems to be a good candidate for
handling the drop event.
*
* @return true if the action this it should handle the drop event.
*/
public abstract boolean accept();
/**
* Performs the drop action.
*
* @param monitor a progress monitor for showing the progress of
the current event.
*/
public abstract void perform(IProgressMonitor monitor);
/**
* Returns the dropped data.
*
* @return the dropped data.
*/
public Object getData() {
return data;
}
/**
* Returns the object that the data was dropped on.
*
* @return the object that the data was dropped on.
*/
public Object getDestination() {
return destination;
}
/**
* Called by framework to initialize the action.
*
* @param element2 the extension configuration element
* @param event2 the drop event.
* @param destination2 the object that the data was dropped on.
* @param data2 the data that was dropped.
*/
public void init( IConfigurationElement element2,
DropTargetEvent event2, int location2,
Object destination2, Object data2 ) {
this.element=element2;
this.event=event2;
this.location=location2;
this.destination=destination2;
this.data=data2;
}
/**
* The drop event.
* @return Returns the drop event.
*/
public DropTargetEvent getEvent() {
return event;
}
/**
* This does not always make sense for the drop event. But in
the case that the component is a jface viewer then this method will
indicate the
* location where the drop is taking place (before, on or after
the destination object).
*
* @see ViewerDropAdapter#getCurrentLocation()
*
* @return If the component is not a viewer this will always
return [EMAIL PROTECTED] ViewerDropAdapter#LOCATION_ON} otherwise it will be
one
of the LOCATION_*
* values.
*/
public int getViewerLocation() {
return location;
}
}
Jesse
On 14-Mar-06, at 12:22 PM, M.S.Bachler wrote:
> Hi!
>
> That's great.
> (I thought it was just me being really thick, and not spotting how to
> get the x,y).
>
> Thanks for adding these changes.
>
> I still can't download the source code at the moment - we do use a
> proxy and I have a feeling it must be blocking some of the command
> Subversion
> needs - I will see IT tomorrow about it.
>
> As I can't get to the source code - are there any javadocs on these
> changes so I know what methods/variables are now available.
>
> Thanks
>
>
> Michelle
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Jesse
> Eichar
> Sent: 14 March 2006 19:08
> To: User-friendly Desktop Internet GIS
> Subject: Re: [udig-devel] Shapefiles
>
>
> Ok so a change of plans.
>
> I've changed the API slightly. Shouldn't bother you too much, all the
> information is still there in the IDropAction class, now I've added
> the getEvent() method to the IDropAction class. It has the x,y
> location of the event.
>
> I think I've cleaned things up a little so you shouldn't have to worry
> about any other classes besides the IDropAction (before the
> UDIGDropHandler was accessible from the IDropAction) I've changed
> that but made sure that all the information is still available in the
> IDropAction.
>
>
> Jesse
>
> On 14-Mar-06, at 9:33 AM, Jesse Eichar wrote:
>
>> Truthfully this is a good question. I think you've identified
>> another short coming of this API. I am going to make 3 changes to
>> UDIGDropHandler.
>>
>> 1. I'm going to change getLocation to return a Point which will be
>> the x,y coordinates of the drop event relative to the component that
>> the component is dropped on. 2. I'm going to add the method
>> getViewerLocation() that will return ON, BEFORE and AFTER locations.
>> (That is what getLocation() currently does)
>> 3. I'm going to add a method isViewer() so you can determine if the
>> control is a viewer and if you should use getViewerLocation() or
>> getLocation().
>>
>> You'll have to download tonights nightly build.
>>
>> (Sorry for the hard time you are having but DND has been a real
>> headache for me to figure out, never mind do right)
>>
>> Jesse
>>
>> On 14-Mar-06, at 2:19 AM, M.S.Bachler wrote:
>>
>>> Hi
>>>
>>> Sorry about yesterdays rant.
>>>
>>> If you have not lost all patients with me, I would really appreciate
>>> it if anyone could tell me how I get the x, y coordinates of the
>>> drop from
>>> my IDropAction class.
>>>
>>> Thanks
>>>
>>> Michelle
>>>
>>> -----Original Message-----
>>> From: [EMAIL PROTECTED]
>>> [mailto:[EMAIL PROTECTED] On Behalf Of
>>> M.S.Bachler
>>> Sent: 13 March 2006 11:04
>>> To: User-friendly Desktop Internet GIS
>>> Subject: RE: [udig-devel] Shapefiles
>>>
>>>
>>> Hi!
>>>
>>> Thanks everyone for your various inputs.
>>> I am still not sure what I am doing (I have decided I am just
>>> thick!).
>>>
>>> I can't see how the DataUtility way or creating a FeatureType passes
>>> in the x,y of the point. Then again, I can't even figure out how I
>>> get the x, y coordinates of the drop from my IDropAction class in
>>> order to create the coords for my Point class in the first place? I
>>> have run around the API, but can't figure it out.
>>>
>>> Is there really no example code out there that I can study to help
>>> me
>
>>> understand things better. I am unable to download the source code
>>> with Subversion (I did write to the list about this but no one
>>> replied). I
>>> need the equivalent of "uDig for Dummies" book.
>>>
>>> Being a Java developer for many years I thought this project would
>>> be
>
>>> relatively easy. But I think having no familiarity with Eclipse or
>>> GIS at all, has really not helped me. While Eclipse is becoming more
>>> familiar, 'GIS speak' is still a mistery. I think what seems
>>> obvious to
>>> many of you when talking about the code, just escapes me.
>>>
>>> I know people are reluctant to spoon feed me the code I need. I know
>>> I need to go through the pain barrier and try and understand it all
>>> myself. But it really hurts, and for various reasons the timescale
>>> of my project has been shrunk, and I am in danger (for the first
>>> time in
>>> my lief!), of not completing something, and having to say I can't
>>> do it.
>>>
>>> I think I have just not reached that eureka moment, when everything
>>> suddenly clicks into place. I hope it happens soon! I still have a
>>> head full of floating jigsaw pieces.
>>>
>>> Meanwhile, if someone could help me with how I get the x,y of the
>>> drop, that would be great.
>>>
>>> Michelle - ( with a heavy cold - feeling rather sorry for myself :-
>>> ( - going to get a cup of tea )
>>>
>>> -----Original Message-----
>>> From: [EMAIL PROTECTED]
>>> [mailto:[EMAIL PROTECTED] On Behalf Of Jody
>>> Garnett
>>> Sent: 11 March 2006 08:58
>>> To: User-friendly Desktop Internet GIS
>>> Subject: Re: [udig-devel] Shapefiles
>>>
>>>
>>> You guys are working to hard, I wrote a parser method I never wanted
>>> to do this stuff twice.
>>> - http://udig.refractions.net/docs/api-geotools/org/geotools/data/
>>> DataUtil
>>> ities.html
>>>
>>> The format is silly, but it is in the javadocs:
>>> - http://udig.refractions.net/docs/api-geotools/org/geotools/data/
>>> DataUtil
>>> ities.html#createType(java.lang.String,%20java.lang.String)
>>>
>>> basically:
>>> "name:String,age:Number,position:Point,*destination:Point"
>>> Where the * indicates the default geometry ..
>>>
>>> Other useful stuff:
>>> - http://udig.refractions.net/docs/api-geotools/org/geotools/
>>> feature/
>>> Featu
>>> reTypes.html
>>>
>>> Jody
>>>>
>>>>
>>>> M.S.Bachler wrote:
>>>>>
>>>>> Hi!
>>>>>
>>>>> Silly question.
>>>>>
>>>>> Earlier you helpfully gave me a code snippet to create a new
>>>>> shapefile.
>>>>>
>>>>> IndexedShapefileDatastoreFactory fac=new
>>>>> IndexedShapefileDataStoreFactory();
>>>>>
>>>>> ShapefileDataStore ds=fac.createDatastore(url);
>>>>>
>>>>> // I assume this is the URL of the new shapefile I want it to
>>>>> create?
>>>>>
>>>>> GeometryFactory gf = new GeometryFactory();
>>>>>
>>>>> ds.createSchema( featureType );
>>>>>
>>>>> // Here I got lost. Started to investigate FeatureType and felt
>>>>> like I was walking through tar.
>>>>>
>>>> I did some stuff with FeatureType the other day... trying to create
>>>> a new Feature from scratch. Here is the code I found to create a
>>>> new
>>>> FeatureType:
>>>> AttributeType geomAttr =
>>> AttributeTypeFactory.newAttributeType("the_geom", LineString.class);
>>>> FeatureType ftRoad =
>>> FeatureTypeBuilder.newFeatureType(new AttributeType[] {geomAttr},
>>> "road");
>>>>
>>>> // WKTReader wktReader = new WKTReader();
>>>> // Point geometry = (Point) wktReader.read
>>>> ("POINT
>>> (" + lat + " " + lon + ")");
>>>> GeometryFactory geomFactory = new
>>> GeometryFactory();
>>>> LineString geometry =
>>> geomFactory.createLineString(coords);
>>>> Feature theRoad = ftRoad.create(new Object[]
>>>> {geometry}, "myRoad");
>>>>
>>>>
>>>> This example Feature only has one attribute which is the geometry,
>>>> the_geom. You can create and add other attributes in the
>>>> AttributType[] and Object[] if needed.
>>>>
>>>> These classes are from the org.geotools.feature package.
>>>>
>>>> Hopefully you may find this useful. I'm not sure if this is the
>>>> most
>
>>>> up-to-date way of doing it, but it worked for me.
>>>>
>>>> Mark
>>>>
>>>> --
>>>> This message has been scanned for viruses and dangerous content by
>>>> *MailScanner* <http://www.mailscanner.info/>, and is believed to be
>>>> clean. _______________________________________________
>>>> 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
>>> _______________________________________________
>>> 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
>>
>> _______________________________________________
>> 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
> _______________________________________________
> 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
_______________________________________________
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