Raba - Defend your code RSS 2.0
# Friday, April 10, 2009

This post inspired by Gal Ochana.

Gal is a new gifted programmer at my team, she presented a great presentation about Linq to XML - you can download code here.
The great bonus at her presentation was the Linq to Kml Sample, I would like to share this with you.

The kml itself is an XML file at our sample it looks like this:

   1: <?xml version="1.0" encoding="UTF-8"?>
   2: <kml xmlns="http://www.opengis.net/kml/2.2">
   3:     <Placemark>    
   4:         <name continent="America">America</name>    
   5:         <description>Attached to the ground. Intelligently places itself at the height of the underlying terrain.</description>    
   6:         <Point>      
   7:             <coordinates>-100.0822035425683,37.42228990140251,0</coordinates>    
   8:         </Point>  
   9:     </Placemark>
  10:     <Placemark>    
  11:         <name continent="Africa">Africa</name>    
  12:         <description>Attached to the ground. Intelligently places itself at the height of the underlying terrain.</description>    
  13:         <Point>      
  14:             <coordinates>20.0822035425683,20.42228990140251,0</coordinates>    
  15:         </Point>  
  16:     </Placemark>
  17:     <Placemark>    
  18:         <name continent="Asia">Asia</name>    
  19:         <description>Attached to the ground. Intelligently places itself at the height of the underlying terrain.</description>    
  20:         <Point>      
  21:             <coordinates>42.0822035425683,33.42228990140251,0</coordinates>    
  22:         </Point>  
  23:     </Placemark>
  24:     <Placemark>    
  25:         <name continent="Europe">Europe</name>    
  26:         <description>Europe</description>    
  27:         <Point>      
  28:             <coordinates>100.0822035425683,62.42228990140251,0</coordinates>    
  29:         </Point>  
  30:     </Placemark>
  31: </kml>


You can read more about Kml here.


Screen-shot of the above kml in the ArcGis-Explorer:

You can see in the above Kml file sample the continents represented as a simple points, of course you can extend it to include polygons, poly-lines or anything else that valid within KML standard.
The only things that differs Kml from the known Xml file is the namespace that we will need to handle in our code, let's see the query itself:

   1: XNamespace ns = "http://www.opengis.net/kml/2.2"; 
   2:  
   3: XDocument kmlDoc = XDocument.Load(InputKml);
   4:  
   5: var result = from placemark in kmlDoc.Descendants(ns + "Placemark")
   6:              where (placemark.Element(ns + "name")
   7:                              .Attribute("continent").Value == 
   8:                              Continents.SelectedItem.ToString())
   9:              select placemark;

 

line 1: declare the full namespace that will be used for the attributes and Tags
line 3: loading the kml input file
line 5-9: run a simple query to select a single continent, pay attention to the namespace that we concatenate for selecting the right node.

Here you can see a screen-shot with the result of the above query using the "Asia" continent as the selected item.

Enjoy.

Friday, April 10, 2009 10:03:14 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
.Net 3.5 | C#3.0 | LINQ | GIS | AGX
# Monday, February 11, 2008

We are using the ArcGis Explorer as our 3d-Browser, and we would like to create a task.config file for each task. You can read more at my last post about Load config file dynamically (here).

Why this Architecture good for us?
Every one can install its explorer on his computer without any problem, we would like to add our own Task-Specific configurations for example: server-names to connect to, task-screen-size, links to web sites etc.
first, such details you cannot be save to the AGX-installation directory because it already installed. second, we would like to send them again and again every time the task will be updated and downloaded.

Any way, after reading this we still have two questions to answer:

1) how to get to the tasks directory
2) how to find our specific task

The answers for those questions are pretty simple:
1) To get to the task directory you should use this parameters:

   1:  Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\ESRI\ArcGIS Explorer\Tasks";

This answer will solve you the "how to found the tasks directory programmatically" but you'll still have to find the specific task directory that is interesting you.
Anyway, this is good but not good enough. I would like the E2 API to give me its Environment parameters and not to force me to code it by myself. It smell like something that can be change... and I'll be glad if the people at the ArcGis Explorer will create something like: public static class E2Environemnt which will implement such property. For now: we implement our own Environment extensions.

2) To Find the specific task you should dig the black box of E2 and you will find this cool factory:

   1:  ESRI.ArcGIS.E2API.E2TaskFactory factory = new ESRI.ArcGIS.E2API.E2TaskFactory();
   2:  string taskDirectoryName  = factory.GetTaskSubfolderNameFromAssemblyName(currentTask); 

So What's the catch I've asked? This is an internal implementation, ESRI don't like you if you'll use it... (you can read more about my question in the AGX forum). And I will ask just one simple question, why?! why not to make it internal or even private class. why we should read it at the XML comments?!

And here is my preferred solution (as Rob answered in the ArcGis Explorer forum), it make the job for me right now and it is the simple way to do it:

   1:  System.Reflection.Assembly.GetExecutingAssembly().Location;

Enjoy.

Monday, February 11, 2008 6:10:38 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
.Net 2.0 | GIS | AGX | Software Development

There are time you would like to load your configuration data from a specific config file or maybe even from the config file but not from the main one, I'll explain it using an example from the real world (last week refactoring).
We have many client which run the ArcGis Explorer (AGX) client (Geographic application like Google Earth), this client can be installed on each and every client, and it has its own configuration files. Within our team we write tasks that running on that AGX. while opening the application it will download to your profile directory the relevant DLL's for running those tasks. but hey those DLL's will be in a separate directory, neither in the GAC nor in the AGX executable directory. You can find many examples for such scenarios.


Here you can see the two different directories: one for the E2.exe and its config file, and the specific task DLL's and its config file (Sample.dll.config)

All we wanted to make is a Task specific configuration. so we would like it to work on every other task we will create.
First you might know this bunch of code, this will help you load the Sample.dll.config file from the wanted directory (The Task directory).

   1:  // Get the application configuration file path.
   2:  string exeFilePath = @"C:\ShaniData\Projects2008\ConfigHandlerDemo\Sample.dll.config"; 
   3:   
   4:  // Map to the application configuration file.
   5:  ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
   6:  configFile.ExeConfigFilename = exeFilePath;
   7:  System.Configuration.Configuration config =
   8:  ConfigurationManager.OpenMappedExeConfiguration(configFile,
   9:  ConfigurationUserLevel.None);
  10:              
  11:  ConfigurationSection sec = config.GetSection("MailManagerConfiguration");

In this situation we should use the .Net default ConfigurationSection implementations (for example: the ApplicationSettingsSection). Those of you who think of using the DictionarySectionHandler or NameValueSectionHandler will found it returning the DefaultSection instead.

Pay also attention that your code is running from the AGX installation directory so if you'll write your own section it won't work unless it was installed on the given computer (in GAC or in the AGX installation directory).

Monday, February 11, 2008 3:38:38 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
.Net 2.0 | GIS | AGX
# Friday, December 21, 2007

The new version of AGX is out, you can found more details in here.

Here are some things I found out:

  • My old tasks works
  • Tab index (inside the tasks) is finally working properly
  • The streaming looks slow - even very slow I'm not sure if this is because of my networks problems or because of ESRI's servers but it was better with the previous version
  • Better handling the outer links (having a bug while opening a site it also opens: "about:blank" empty window near it)
  • More cool icons for instead of the simple pushpins

Still (really) missing

  • Scale bar (on the bottom of the page, or even in task)
  • Simple "Add connection" to Google Maps (servers) & Virtual Earth (servers)
  • SDK for 2008 (The given one fits to 2005 only)

Here is a simple result I make using the new popup window:

Enjoy.

Friday, December 21, 2007 1:42:07 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
GIS | AGX
# Wednesday, August 15, 2007

There is a new version of ArcGis Explorer (410).

I only made one test for simple old version of one of my tasks, it still works.
It looks lie they almost didn't changed the templates of creating new tasks.

API Changes (didn't test it yet, only read about it):

  • RemoveLayerCache(Layer) - delete the cahe of a given layer, this one is great!
  • CacheType - {Permanent, Session, None} - indicates the way ArcGis Explorer caches the layer.

I will keep checking and update you ASAP.

Wednesday, August 15, 2007 11:29:41 PM (GMT Daylight Time, UTC+01:00)  #    Comments [1] - Trackback
AGX
# Saturday, May 26, 2007

I've finally found some time to explore the nmf format and the AGX capabilities a little bit more than I used to read at the ESRI site.

In my office we made the first installation on production of the AGX in Israel and I'm pretty sure we are the first in the world.
One of the problems with being first - is the lack of knowledge and documentation, moreover this product (AGX 350) has many bugs.

despite all those cons I am very happy with this decision, as I wrote in my last post.

Today I will light your eyes with two properties I found, Visible & HideFromContents
Visible - is pretty straight forward, true - will show the layer on screen, the false - will hide it from your screen.
HideFromContents - is also straight forward but I didn't know it exist till today, this will decide whether your layer will be in the Table of Contents (TOC) or not.

I played a little bit for you - I hope those screen shots will help you to remember this post.

 
{Visible=true,HideFromContents=false} the layer(Bountiful_images) can be seen and can be managed by the TOC on the left.


{Visible=true,HideFromContents=true} the layer(Bountiful_images) can be seen but can't be managed by the TOC on the left (magic-layer).


{Visible=false,HideFromContents=true} there is a different layer on the screen than the layers above moreover you can't manage it using the TOC.

Pay attention that in the last (Visible = false, HideFromContent=true) you cannot see the layer at all, but you can find it in tools -> manage layers .
The problem is that you will never see this layer :). bug or feature, you decision.

Business logic as a bonus:
One of the customers came to me and told me they want to see a specific layer but stop users from managing (showing\hide) it.
To me it sounds stupid, but hey this is the customer decision, and it won't cost me a thing.

Saturday, May 26, 2007 1:22:19 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
GIS | AGX
# Sunday, March 25, 2007

After writing a special post about Changing the annoying ESRI Icon, I found another way to do those things at the ofiicial ESRI site.
Read this post about changing\adding skin.

 

 

Sunday, March 25, 2007 11:45:28 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
AGX
# Saturday, February 24, 2007
We are developing a new application over the AGX API. ESRI give us a small and powerless API, which you must use this default window with this default images and menus. But we would like to change those capabilities...
Saturday, February 24, 2007 11:26:29 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
.Net 2.0 | AGX | Software Development
Archive
<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Shani Raba
Sign In
Statistics
Total Posts: 139
This Year: 6
This Month: 0
This Week: 0
Comments: 97
Cool Stuff
Add to Technorati Favorites
Themes
Pick a theme:
All Content © 2010, Shani Raba
DasBlog theme 'Business' created by Christoph De Baene (delarou)