Thursday, December 25, 2014

Issues observed in "ESRI GeoEvent Processor"


 
When working with "ESRI GeoEvent Processor", I noted couple of issues.

Issue 1 :

If the "ESRI GeoEvent Processor" service is updating or adding new GIS features based on the "GeoEvent", it will work fine for few hours and then the server performance will be extremely slow and will become unusable at some time. Then we have to either restart the GEP Service and ArcGIS Server Service or restart the server itself.

After some trial and error, I found out that, if the "ArcSDE" data is a "Versioned" data then this issues happens. In the "Unversioned" ArcSDE data this will not occur.

Issue 2:

In the "GeoEvent Processor" web service, if you add an output to add new GIS feature, there is an option to "Delete Old Features". Even if you enable this, it will not delete the old features. The reason is, it performs a query like DATE_TIME < '[Some Date Time Value]'. For some reason this query does not contain the proper SQL Date Time query syntax and hence it fails to delete any features.

The only work around is to periodically delete the old features from the ArcGIS REST endpoint feature service url.

Hope these tips are helpful. If there are any new solutions, please add it in the comments section below.

Happy Holidays

Cheers
Adam

Saturday, November 29, 2014

Calling remote JSON data web service url using

Here  is a sample code to call remote JSON data web service using JQuery Ajax call.

Use this simple javascript function when calling remote JSON data web service.

function callRemoteWebService(){
    var url = "htttp://someremote/web/service/url" ;
    $.ajax({
       
url:url,
        type: 'GET',
        dataType: 'json',
        timeout: 20000,
        error: function(errData){
            handleError(errData);
        },
        success: function(successData){
            handleError(
successData
);
        }
    });
}


Happy Coding !



Monday, October 27, 2014

Access data across domains


When working with jQuery and JavaScript, there was a need to access a "Remote Web Service" which was hosted from a different server.

Since I was debugging using my local laptop, the application was throwing errors like "Cross-domain policy file missing" or "Unable to access data across domains".

After some research, I found that we can make both Internet Explorer and Chrome browser work with data from different domains.

In Internet Explorer do this.

Under Security Tab, click "Custom Level" button. Scroll Down to Miscellaneous Section and choose "Access data sources across domains" - Enable.

In Chrome do this.

Create a simple short-cut on Desktop. Add the following line as the "Start up Application" for the short-cut.

"C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe" --allow-file-access-from-files --disable-web-security

This will open the Chrome Browser in a different mode capable of accessing data across domains.

Hope this tip helps.

Happy Coding !
 

Thursday, September 25, 2014

Working with ESRI GeoEvent Processor


I was asked to setup the “ESRI GeoEvent Processor” for one of our projects. It was quite exciting to work with it. We can simulate real-time data streams. The real-time data streams can trigger events. We can use these events to build additional logic based on our business needs.

First it was not clear where to start and what are the steps to do. After figuring it out, I thought of documenting here so it will give a starting point for anyone who is interested.

These are the main things to focus when working with “ESRI GeoEvent Processor”.
  1. Prepare the GIS data exactly the way you want for your business needs.
  2. Prepare the “Real Time Data” stream. This can be a series of Latitude and Longitude values with other information. For example flight data or truck data. Any data which contains a stream of X and Y values with time stamp that can be mapped on the Map.
  3. In the ESRI GeoEvent Processor, create the right kind of “Inputs” and “Outputs”. There are several choices here. Based on the business requirement the correct one should be chosen. A little bit of planning and few trails and error will produce expected results.
  4. Use the “Inputs” and “Outputs” to create the “GeoEvent Service”. This “GeoEvent Service” will use the “Inputs” and “Outputs” to produce the desired results.

Based on the “GeoEvent”, it is possible to update an existing GIS Feature in a “FeatureService” in ArcGIS Server REST endpoint. It is also possible to add New GIS Features.

Hope you got an idea where to start!

Happy configuring.

Cheers
Adam

 

 

 

Sunday, August 24, 2014

HTTP Web Service using ASP.NET Web API

Creating HTTP WebService using ASP.NET Web API is really simple.
 
After few reading/coding work, I got an idea on what needs to be implemented.
 
1. Make sure the routing table is configured correctly like shown below. The 'WebApiConfig' class will be present in the folder 'App_Start' folder. Note down the 'action' text added in the route.
 
public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Web API routes
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
 
 
2. Create the Controller Class. See the sample class 'ManagerController' shown below. This class should be derived from 'ApiController'. Also note down the first portion of the controller class name 'Manager' and the action name 'getSomeInfo'. This will be used later when you invoke the 'HTTP Web Service'.
 
public class ManagerController : ApiController
{
        #region Public Web Methods
        [HttpGet]
        [ActionName("getSomeInfo")]
        public SomeOutputClass SomeGetWebFunction(string someInput)
        {
     // Some code goes here.
     // This should return SomeOutputClass.
  }
}
 
These are the only two steps we need.
 
Compile the application and host it in IIS Server and give some application name. For example 'TestApp'.
 
The HTTP Web Service is ready.
 
Simply call the 'WebService' as shown below and you should get the results as 'JSON' text format.

The HTTP Web Service call will be invoked like shown below.
 
 
There are many details in ASP.NET Web API. The idea I have provided will simply get you started.
 
Read more information for further details.
 
Happy Coding !
 
Cheers
Adam

 

Monday, July 28, 2014

Connect to remote SQL Server over the Internet


I installed SQL Server 2008 R2 edition on a Virtual Machine (VM). I was supposed to access this SQL Server from my laptop over the internet.

I created the .udl file on my laptop and tried to access this remote SQL Server in the VM. It was not connecting. Tried many things but still unable to connect to the remote SQL Server on the VM.

(A quick note on the UDL file. Create a simple text document and change the extension to .udl. Double-click the UDL file. This will provide tools to establish a connection to any database based on the drivers available on the laptop. We can establish the connection to a remote server. If you open the .udl file in a notepad you can see the complete connection string. This connection string can be used in any application to communicate with the database.)

After checking few internet pages here is what I found. There are two items to check and fix.

Item 1:

In the SQL Server Configuration Manager, check the “Protocols”. The “TCP/IP” protocol should be enabled and make sure the IP address uses the port 1433. This is the default SQL port.

Item 2:

Check the Windows Firewall Settings. Add an “Inbound Rule” to allow communication through the port 1433.

After fixing these two items, I was able to communicate to my remote SQL Serve from my laptop over the Internet.

Hope this tip helps you.

Sunday, June 22, 2014

Creating Dynamic Radio Button Controls in Silverlight MVVM model

There was a need to create dynamic "Radio Button" controls in one of my projects. This was a Silverlight MVVM project.

Since the "View" is isolated from "ViewModel" and connected only through binding, it was not clear on how to do this task.

After few research I found the answer.

This is the code that needs to go on the XAML side. Note the "ItemsControl" element. The itemssource will take in a List of RadioButtonClass.

<Grid DataContext="{StaticResource ViewModel}">
        <StackPanel>
            <ItemsControl ItemsSource="{Binding RadioButtonClassList}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <RadioButton GroupName="OneGroup" IsChecked="{Binding IsSelected}" Content="{Binding RadioButtonName}"></RadioButton>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </StackPanel>
 </Grid>


Note the binding properties (IsSelected and RadioButtonName) in the "RadioButton" control.

The "RadioButtonClass" can be defined something like this.

public class RadioButtonClass : INotifyPropertyChanged
{
   public string RadioButtonName;
   public bool IsSelected;
}

In the "ViewModel" class if you add a property which is a List like this List<RadioButtonClass> and bind it to the View as shown in the above XAML snippet (<Grid DataContext="{StaticResource ViewModel}">) then the RadioButtons will show up. The number or radio buttons is equal to the number of items in the List.

Hope this tip helps.

Happy Coding !


 

Monday, May 19, 2014

ESRI Legend Control - Show and Hide Sliders

In the ESRI Legend Control, "DataTemplate" can be used to display slider "usercontrol" to control the opacity of the Layer.
 
Here is the XAML content where the slider "usercontrol" is used.
 
      
<esri:Legend Grid.Row="1" x:Name="legendControl" VerticalAlignment="Top" LayerItemsMode="Tree"
ShowOnlyVisibleLayers="False" Margin="5,5,5,5" ><esri:Legend.MapLayerTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox Content="{Binding Label}"
IsChecked="{Binding IsEnabled, Mode=TwoWay}"
IsEnabled="{Binding IsInScaleRange}" >
</CheckBox>
<Slider Maximum="1" Value="{Binding Layer.Opacity, Mode=TwoWay}" Width="50" Loaded="Slider_Loaded" Tag="{Binding Layer}" />
</StackPanel>
</DataTemplate>
</esri:Legend.MapLayerTemplate>
<esri:Legend.LayerTemplate>
<DataTemplate>
<CheckBox Content="{Binding Label}"
IsChecked="{Binding IsEnabled, Mode=TwoWay}"
IsEnabled="{Binding IsInScaleRange}" >
</CheckBox>
</DataTemplate>
</esri:Legend.LayerTemplate>
</esri:Legend>


But what happens, if the user should see Slider usercontrol only for certain Layers and for certain Layers it should NOT be shown ?

There are many ways to do this. But here is one simple method.

In the Slider "usercontrol" add the following event and tag in the XAML content.

Loaded="Slider_Loaded" Tag="{Binding Layer}"

In the code behind simply use some logic like this.

private void Slider_Loaded(object sender, RoutedEventArgs e)
{Slider slider = sender as Slider;
Layer layer = slider.Tag as Layer;
if (layer.ID == "SampleData") slider.Visibility = System.Windows.Visibility.Collapsed;
}

If the "Layer.ID" matches with that "specific layer name", then the slider will not be displayed.

Hope this helps !

Have fun coding :)

Cheers
Adam





 

Saturday, April 19, 2014

Get color from HTML color string

Here is a quick code snippet to get color from HTML color string.

private Color GetColorFromString(string inStringColorCode)
{

Color togoColor = Colors.Transparent;
try
{

byte alpha = Convert.ToByte(Convert.ToInt32(inStringColorCode.Substring(0, 2), 16));

byte red = Convert.ToByte(Convert.ToInt32(inStringColorCode.Substring(2, 2), 16));

byte green = Convert.ToByte(Convert.ToInt32(inStringColorCode.Substring(4, 2), 16));

byte blue = Convert.ToByte(Convert.ToInt32(inStringColorCode.Substring(6, 2), 16));

togoColor = Color.FromArgb(alpha, red, green, blue);

}

catch (Exception ex)
{

MessageBox.Show("Error when converting color ARGB code " + inStringColorCode + ". It must be of length 8 characters." + ex.ToString(), "Error", MessageBoxButton.OK);
}
return togoColor;
}

Happy Coding !

Sunday, March 23, 2014

Using Events and Delegates in Visual C#.NET


Here are the steps to create events and delegates in .NET.
 
STEP 1:

In the Child Control which raises the event, you should have the following:

public delegate void ZoomtoMapEventHandler(object sender, ClassQueryResultsSet CQRe);

public event ZoomtoMapEventHandler ZoomtoMapEvent;

where the ClassQueryResultsSet is as follows :

public class ClassQueryResultsSet : EventArgs
                {
                                public DataSet QueryResultsDataSet ;
                                public string QueryResultsTableName ;
                                public string KeyFieldName ;
                                public ClassQueryResultsSet()
                                {
                                                //
                                                // TODO: Add constructor logic here
                                                //
                                                QueryResultsDataSet = null ;
                                                QueryResultsTableName = null ;
                                                KeyFieldName = "" ;
                                }
                }

Also when invoking the event check for null and do it as shown below:

                                                                if (ZoomtoMapEvent != null)
                                                                {
                                                                                ZoomtoMapEvent(this, Res) ;
                                                                }
                                                                else
                                                                {
                                                                                MessageBox.Show("ZoomtoMapEvent is Null !") ;
                                                                }

STEP 2

In the MAIN PARENT Program, the event is declared like below

x.userControlQuerySingleTable1.ZoomtoMapEvent += new WindowsControlLibrarySingleTable.UserControlQuerySingleTable.ZoomtoMapEventHandler(x.ShowMaptoUser)  ;

 
Also the function into which the control should come in should have the same signature as shown below:

public void ShowMaptoUser(object o, ClassQueryResultsSet e)
{
                MessageBox.Show("Calling ok" + e.QueryResultsTableName) ;
}

Using this events and delegates will come in handy when passing information from one class to another.

Happy coding.

Cheers
Adam

Monday, February 24, 2014

Simple Slideshow using timer, javascript and JQuery


Here is the code to create a simple slideshow using timer, JavaScript and JQuery.

The html file contents should be like this which has all the images to show up.

<div class="galleryImages">
<img src='Images/Slides/0.png' alt="" />
<img src='Images/Slides/1.png' alt="" />
<img src='Images/Slides/2.png' alt="" />
<img src='Images/Slides/3.png' alt="" />
</div>
 
The 'galleryImages' class is defined like this.

.galleryImages {
position: relative;
height: 350px;
width:700px;
overflow: hidden;
border:solid;
border-color:black;
border-width:thin;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
-khtml-border-radius: 15px;
border-radius: 15px;
margin:10px;
}
 
.galleryImages img {
position: absolute;
top: 0;
left: 0;
}


The JavaScript code should be like this.

var slideShowTimer;
var imageId = 0;
var galleryImages;
var transitionSpeed = 500;

function PerformInitialization() {
SetupTimer();galleryImages = $('.galleryImages img');
}
 
function SetupTimer() {
slideShowTimer = setInterval(ChangePhoto, 3000);
}
 
function ChangePhoto() {
galleryImages.eq(imageId).stop(true, true).animate({ opacity: 0 }, transitionSpeed);
imageId++;if (imageId >= galleryImages.length) {
imageId = 0;
}
galleryImages.eq(imageId).stop(true, false).animate({ opacity: 1 }, transitionSpeed);
}

Make sure to call PerformInitialization() function during "onload" of the body of the html file.

Also make sure to add these "JQuery" references.

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js"></script>

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/jquery-ui.min.js"></script>
   
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/flick/jquery-ui.css" rel="stylesheet" type="text/css" />

Have fun. Happy coding.

Cheers
Adam

All Blogs so far ...