1

I've written a little java add-in button for ArcDesktop 10.4, in eclipse, which makes a new ArcMap layer with some points. (NOT Runtime) My goal is to assign a picture as the symbol for each of these points. I have success on my machine, but I can't figure out how to make my picture accessible to all future users.

Here's my class, part of larger program, which does work, but image currently only comes through from path on my own computer:

public class SymbologyChanger {

public SymbologyChanger(ArrayList<Point> pointsForTheLayer, IMap currentMap) throws AutomationException, IOException {

    IGraphicsContainer graphContainer = (IGraphicsContainer) currentMap.getActiveGraphicsLayer();

    for (int i = 0; i < pointsForTheLayer.size(); i++) {
        Point point = (Point) pointsForTheLayer.get(i);

        double symbolSize = 15;
        IPictureMarkerSymbol picSym = new PictureMarkerSymbol();
        picSym.setSize(symbolSize);
        // http://resources.esri.com/help/9.3/ArcGISDesktop/ArcObjects/esriDisplay/esriIPictureType.htm

        picSym.createMarkerSymbolFromFile(1, "C:\\Users\\userName\\eclipseWorkspace\\java_project\\images\\my_image.bmp");

        IMarkerElement markerElement = new MarkerElement();
        markerElement.setSymbol(picSym);
        IElement element = (IElement) markerElement;
        element.setGeometry(point);
        graphContainer.addElement(element, 0); 
        }
    }
}

So it's this particular line:

picSym.createMarkerSymbolFromFile(1, "C:\Users\userName\eclipseWorkspace\java_project\images\my_image.bmp");

which is my problem. I've placed the image in the project images folder, along with the button icon. The button icon totally works, but for the points symbol, I've tried:

picSym.createMarkerSymbolFromFile(1, "images\my_image.bmp");

And this does not work. Again, I get the image I want for the point symbol, but how to set the path correctly to share with others? I need the image to work as the point symbol with all machines, not just my own.

6
  • Did you try putting the file in a network share folder? \\someserver\somefolder\my_image.bmp – Kirk Kuykendall Jan 28 '20 at 18:07
  • Can you embed the file in your program? – danielm Jan 28 '20 at 22:11
  • I can embed the file in with the package, but the 2 ways to set the image with IPictureMarkerSymbol are: .createMarkerSymbolFromFile(#, stringToFile); OR .setPictureByRef(); Which I'm having trouble figuring out how to make work with an embedded file. resources.esri.com/help/9.3/arcgisengine/java/api/arcobjects/… – lep Jan 29 '20 at 18:15
  • Concerning putting the file in a network share folder @Kirk Kuykendall, each user assigns a different letter of the alphabet to represent the shared drive on their PC, that is not standardized. So that still leaves the image as string-dependent, seeking a file path, rather than grabbing the image as part of the program. So I'm stumped. – lep Jan 29 '20 at 19:00
0

I wasn't able to find a way to reference an image file saved in my JAR in order to use it for the points in the layer. Even The Horton Machine suggestion, using OSGeo (thanks to Kirk), seems to require a file path / string in order to assign a bitmap image as a point's symbol. My goal was to allow the image to travel with the add-in, rather than place it elsewhere. Alas.

I also tried to find another solution, using IPictureMarker's .setPictureByRef method, but could not discover a way: How to set image for Picture / IPicture for ArcGIS Desktop?

So, I had to let go of my preference and follow @Kirk Kuykendall's first suggestion, which will work 90% of the time, and pair that with an alternate. Now, the point will always produce a new, striking image for my user - even if my .bmp file is misplaced.

The image (bitmap) is in a shared network folder. If the user is unable to find that image file, or if another user should happen to move it in the future, a SimpleMarkerSymbol will replace the image.

If anyone ever has a different solution, though, please do chime in!

Here is the code to create the symbology for points in new layer:

public SymbologyChanger(ArrayList<Point> pointsForTheLayer, IMap currentMap) throws AutomationException, IOException {

    IGraphicsContainer graphContainer = (IGraphicsContainer) currentMap.getActiveGraphicsLayer();

    for (int i = 0; i < pointsForTheLayer.size(); i++) {
        Point point = (Point) pointsForTheLayer.get(i);

        double symbolSize = 15;
        IPictureMarkerSymbol picSym = new PictureMarkerSymbol();
        picSym.setSize(symbolSize);
        // http://resources.esri.com/help/9.3/ArcGISDesktop/ArcObjects/esriDisplay/esriIPictureType.htm

        // https://stackoverflow.com/questions/7481200/how-to-read-file-from-a-shared-location-windows-java
        String ipictureMarkerSymbolStr = "\\\\##.##.##\\sharedFolder\\Image\\my_image.bmp";
        File ipicDefault = new File(ipictureMarkerSymbolStr);

                // user will either see the image in the shared folder OR a big purple circle
                if (ipicDefault.exists() || ipicDefault.isFile()) {
                    IPictureMarkerSymbol ipicMarkSym = new PictureMarkerSymbol();
                    ipicMarkSym.setSize(symbolSize);
                    ipicMarkSym.createMarkerSymbolFromFile(1, ipictureMarkerSymbolStr);
                    IMarkerElement markerElement = new MarkerElement();
                    markerElement.setSymbol(ipicMarkSym);
                    IElement element = (IElement) markerElement;
                    element.setGeometry(point);
                    graphContainer.addElement(element, 0);
                } else {
                    SimpleMarkerSymbol simpSym = new SimpleMarkerSymbol();
                    simpSym.setSize(10);
                    simpSym.setStyle(esriSimpleMarkerStyle.esriSMSCircle);
                    simpSym.setColor(makePtColor());
                    simpSym.setOutline(true);
                    simpSym.setOutlineSize(0.1);
                    simpSym.setOutlineColor(makePtColor());
                    IMarkerElement markerElement = new MarkerElement();
                    markerElement.setSymbol(simpSym);
                    IElement element = (IElement) markerElement;
                    element.setGeometry(point);
                    graphContainer.addElement(element, 0);
                }
        }
    }
    private IColor makePtColor() throws UnknownHostException, IOException {
        // https://www.rapidtables.com/web/color/RGB_Color.html
        RgbColor ptColor = new RgbColor();
        ptColor.setRed((int) (50));
        ptColor.setGreen((int) (0));
        ptColor.setBlue((int) (204));
        return ptColor;
    }
}
2
  • If the image is saved to the JAR, couldn't you write the file to the local user files and reference the image from there? Then it will travel with the add-in. – danielm Feb 12 '20 at 20:10
  • Alas, writing a file to the user's machine from the program runs into some administrator privilege issues in the current setting. Otherwise, yes, that would be fine. Sadly, there seem to only be 2 ways to achieve this with ESRI & Java, the above and that which I could never figure out, here: gis.stackexchange.com/questions/349247/… No responses from GIS Stack Exchange or the GeoNet community concerning Picture / IPicture. So, the solution I used above just had to be sufficient. – lep Feb 18 '20 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.