Saturday, December 22, 2012

Restoring ArcSDE SQL Database from SQL Backup File

In one of my projects I was given a SQL backup file (.bak) file and was told that this is an ArcGIS ArcSDE Database.

My task was to restore it into our ArcSDE Environment.

Here are few simple steps/tips on how to perform this task.

1. Use SQL Restore Command and restore the database.

2. It is very important to restore it to the same 'Original Database Name'. If this is not the case then it will not work correctly.

3. After restoring, in the restored database, there will be many users from the client environment. Verifiy if there is a 'sde' user. If there is a 'sde' user then run the following script in SQL. It is also assumed that in your environment there is a 'sde' user.

EXEC sp_change_users_login 'Update_One', 'sde', 'sde'

4. Make sure your 'sde' login is mapped to the newly restored database. The schema name should be same as the user name which is 'sde'.

5. Verify that the 'sde' user has the following permissions

CREATE TABLE
CREATE PROCEDURE
CREATE FUNCTION
CREATE VIEW
CONNECT
VIEW DATABASE STATE

6. Now establish a connection from 'ArcCatalog' as 'sde' user and you will be able to see the GIS data.

Have fun !

Cheers
Anand

Friday, November 23, 2012

ESRI Javascript API - Adding a Graphic

It's easy to add Graphic on the Map using ESRI's Javascript API.

This function calls to add graphic.

addGraphic(map, getPoint(lngsign, photoLng, latsign, photoLat), photoFileName, photoThumbNail, photoTitle, photoDesc);

This function gets the Point Geometry based on Lat and Long.

function getPoint(lngsign, x, latsign, y) {
    var togoPoint = esri.geometry.geographicToWebMercator(new esri.geometry.Point(lngsign * x, latsign * y, new esri.SpatialReference({ wkid: 4326 })));
    return togoPoint;
}


This function adds the Graphic to the Map Control.
function addGraphic(map, geometry, fileName, thumbnailName, title, description)
{
    var symbol = null;
    var pointSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 0, 255, 0.9]));
    var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1);
    var polySymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.5]));
    var type = geometry.type;
    if (type === "point" || type === "multipoint") {
        symbol = pointSymbol;
    }
    else if (type === "line" || type === "polyline") {
        symbol = lineSymbol;
    }
    else {
        symbol = polySymbol;
    }
    var newGraphic = new esri.Graphic(geometry, symbol);
    var infoTemplate = new esri.InfoTemplate(); infoTemplate.setTitle(title);
    var imageContent = GetImageContent(fileName, thumbnailName, description);
    infoTemplate.setContent(imageContent);
    newGraphic.setInfoTemplate(infoTemplate);
    map.graphics.add(newGraphic);
   
}


Make sure that all these calls are done after the Map control is initialized.
This is the init() function. As you can notice the "onUpdateEnd" function ensures that the map is updated. All other javascript functions can be called after this event has fired.

function init()
{
    adjustWindowDimensions();
    map = new esri.Map("divMap");
    var tiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer");
    map.addLayer(tiledMapServiceLayer);
    var startExtent = new esri.geometry.Extent(-24440281.172008913, -342437.886717527, 2289441.8711969512, 10419895.695832416);
    map.setExtent(startExtent);
    dojo.connect(map, "onMouseMove", showCoordinates);
    dojo.connect(map, "onMouseDrag", showCoordinates);
    dojo.connect(window, 'resize', map, map.resize);
    dojo.connect(map, "onUpdateEnd", hideStatus);
    dojo.connect(map, "onUpdateStart", showStatus);
    dojo.connect(map, "onExtentChange", mapExtentModified);
}
 Happy Coding !

Cheers
Anand
 

Saturday, October 6, 2012

RichTextBox in Silverlight

Team,

Here is a simple code to implement "RichTextBox" in silverlight.

Call this function WriteTextintoRichTextBox() and send in the message to be shown in the textbox.

Happy coding.

Cheers
Anand

The XAML file content:

<Border Background="Red" Width="300" Height="300" VerticalAlignment="Bottom" HorizontalAlignment="Left" CornerRadius="10">
<RichTextBox x:Name="richTextBox" Margin="5,5,5,5" IsReadOnly="True" >
</RichTextBox>
</Border>

The CS file content:

private void WriteTextintoRichTextBox(string toWriteInfo)
{
Paragraph rtbPara = new Paragraph();
Run rtbRun = new Run();
rtbRun.Text = toWriteInfo;
LineBreak rtbLineBreak = new LineBreak();
rtbPara.Inlines.Add(rtbRun);
this.richTextBox.Blocks.Add(rtbPara);
this.richTextBox.SelectAll();
}

Sunday, September 30, 2012

Map Scale in ESRI Silverlight API


To display better scale information on the map, it's recommended to use the following technique.

1.       As always use the ESRI “ScaleLine” control for the Map.

2.       Utilize the property changed event of this control and then compute the scale to display.

Here is the sample code.
 

XAML code:

<StackPanel Orientation="Vertical">
<TextBlock x:Name="textBlockScaleVaue" Text="Scale" Margin="5,5,5,1" Foreground="White" FontSize="10"
FontStyle="Normal" FontWeight="Normal" Opacity="1.0"/>
<esri:ScaleLine Opacity="1.0" Map="{Binding ElementName=mapControl}" Margin="5,1,5,5" IsHitTestVisible="False" Foreground="White"
Name="scaleLine" MapUnit="Miles" PropertyChanged="scaleLine_PropertyChanged" >
</esri:ScaleLine>
</StackPanel>

.cs file code:

private void scaleLine_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
double currentMapscale = scaleLine.USValue;
ESRI.ArcGIS.Client.Toolkit.ScaleLine.ScaleLineUnit currentMapunit = scaleLine.USUnit;
double valueinInches = 0.0;
if (currentMapunit == ESRI.ArcGIS.Client.Toolkit.ScaleLine.ScaleLineUnit.Feet)
{
valueinInches = 12.0 * currentMapscale;
}
else if (currentMapunit == ESRI.ArcGIS.Client.Toolkit.ScaleLine.ScaleLineUnit.Miles)
{
valueinInches = 12.0 * 5280.0 * currentMapscale;
}
this.textBlockScaleVaue.Text = "Scale: 1:" + valueinInches.ToString("#,##0.##");
}

Hope this tip helps.

 Happy programming!

 

 

 

Saturday, August 25, 2012

Reading RSS News Feeds

Here is the code to read RSS feed. Hope this helps someone who is writng a code to read RSS feeds.
The final content will be stored in two arraylists.


                string RSSfeed = "http://rss.cnn.com/rss/cnn_topstories.rss" ;
                ArrayList rawkeyList = new ArrayList();
                ArrayList rawvalueList = new ArrayList();
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.ConformanceLevel = ConformanceLevel.Fragment;
                settings.IgnoreWhitespace = true;
                settings.IgnoreComments = true;
                XmlReader reader = XmlReader.Create(RSSfeed, settings);
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        if (reader.IsEmptyElement)
                        {
                            string emptyElementName = reader.Name;
                        }
                        else
                        {
                            string nameElement = reader.Name;
                            string nestedElementName = "";
                            string textContent = "";
                            reader.Read(); // Read the start tag.
                            if (reader.IsStartElement())  // Handle nested elements.
                            {
                                nestedElementName = reader.Name;
                            }
                            textContent = reader.ReadString();
                            rawkeyList.Add(nestedElementName.ToUpper() + ":" + nameElement.ToUpper());
                            rawvalueList.Add(textContent);
                        } // if IsEmptyElement
                    } // if IsStartElement
                } // while

 

 


 

Sunday, July 29, 2012

Reading Config File in Silverlight

Sometimes it's required to read Configuration File in the Silverlight Application.

The configuration file can be placed in the "ClientBin" folder and accessed from there.

In this function the "SLAppConfigURL" contains the configuration file name.

private void GetConfigData()
{
WebClient xmlClient = new WebClient();
xmlClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(xmlClient_DownloadStringCompleted);
xmlClient.DownloadStringAsync(new Uri(SLAppConfigURL, UriKind.RelativeOrAbsolute));
}

Once the configuration file is read, the program control comes to the below function. The entire file content will be in the "e.Result" varaible. You can deserialize it or read from the string directly at this point.

void xmlClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
string xmlConfig = e.Result;
}

Happy Coding.

Cheers
Anand

Saturday, June 30, 2012

ChildWindow in Silverlight

When using ChildWindow in silverlight, the window closed event was triggering unexpectedly.

After checking the code, we discovered, setting up the DialogResult = true, is automatically closing the window and hence the close event was triggered.

Thursday, May 31, 2012

PictureMarkerSymbol Issue in ArcGIS Silverlight API

Recently I was working with ArcGIS Silverlight  API version 3.0 and Silverlight version 5.0.

I was migrating a previous Silverlight API code to version 3.0. All were working fine, but the PictureMarkerSymbol was not showing up correctly. It was showing blank.

After several debugging minutes, I found out the source element value should be modified slightly as shown below.

<esriSymbols:PictureMarkerSymbol x:Name="MapDefaultIdentifySymbol" OffsetX="36" OffsetY="36" Source="/SolutionName;component/Images/i_about.png" />

Before it was used like shown below.
<esriSymbols:PictureMarkerSymbol x:Name="DefaultIdentifySymbol" OffsetX="35" OffsetY="35" Source="Images/i_about.png" />
Note down the "Solution Name" and the word 'component' in the source value.

All the path and other attributes were same.

I am not sure whether Silverlight 5 or ESRI ArcGIS Silverlight API version 3.0 requires this change.

But with this new combination and the above syntax it works as expected.

Happy coding.

Cheers
Anand

Monday, April 30, 2012

DIV Tag and Transparency

If transparency is 100% then on-click event will not work for div tag.

Sunday, March 25, 2012

Creating Oracle Schema to load data into ESRI ArcSDE

ESRI’s ArcSDE and Oracle Database combination can be tricky sometimes. Here are the steps to create an Oracle Schema and load data into ESRI’s ArcSDE. These steps should be performed after setting up ArcSDE software and running the post install and assuming that the default ArcSDE service is already running in port 5151.

First the Oracle Database and the user must be created. Next the proper permissions have to be provided.

Finally in ArcSDE we need to run the setup script then all is done.

The following script must be run in SQL Plus. Substitute ‘&1’ with username and ‘&2’ with password. This will create the database and provide proper permissions.
CREATE TABLESPACE &1 DATAFILE 'D:\app\oracle\oradata\arcsde\&1..DBF' SIZE 500M AUTOEXTEND ON;

create user &1 identified by &2 default tablespace &1;

alter user &1 quota unlimited on &1;

GRANT CREATE SESSION,
CREATE TABLE, 
CREATE TRIGGER,
CREATE SEQUENCE,
CREATE PROCEDURE,
CREATE INDEXTYPE,
CREATE LIBRARY,
CREATE OPERATOR,
CREATE PUBLIC SYNONYM,
CREATE TYPE,
CREATE VIEW,
DROP PUBLIC SYNONYM,
SELECT ANY TABLE,
ALTER ANY INDEX,
ALTER ANY TABLE,
ANALYZE ANY,
CREATE ANY INDEX,
CREATE ANY PROCEDURE,
CREATE ANY SEQUENCE,
CREATE ANY TRIGGER,
CREATE ANY VIEW,
DROP ANY INDEX,
DROP ANY PROCEDURE,
DROP ANY SEQUENCE,
DROP ANY TABLE,
DROP ANY VIEW,
EXECUTE ANY PROCEDURE,
SELECT ANY SEQUENCE,
ADMINISTER DATABASE TRIGGER
TO &1;

The following script must be run in DOS command prompt. Substitute ‘%1’ with username and ‘%2’ with password and ‘%3’ with ESRI EDN License File Name. This will setup ArcSDE and get it ready.
ECHO Setting Up  %1 with password %2
sdesetup -o install -d ORACLE11G -i 5151:%1 -u %1 -p %2 -l %3.ECP

In ArcSDE, when making connection (assuming 5151 port is running default ArcSDE Service)  make sure the connection is made to the correct schema not to the default SDE schema. Please check the snapshot below. In the sample "ECMV" is the Oracle Schema name which is also the username.

This was tested at ArcSDE 9.3 oracle 11g.

Good luck.

Cheers
Anand


Saturday, February 25, 2012

Silverlight RIA Services - Records count mismatch

Team,

I was working with a Silverlight application which was fetching SQL data using RIA services. While coding I observed that the total number of records in the SQL data table is not matching with the records count in the Silverlight application.


After several debugging hours I found out a very crucial behavior.


All these tables that are coming in through RIA services need a primary key. If there is no primary key then the RIA services might try to pick a unique column on its own. But it’s always a hit and miss. So it’s better to make sure every table even every view that is being fetched through RIA services must have a “Unique Key Field”.


Hope this helps and saves time.


Happy Coding!

Cheers
Anand

Thursday, February 23, 2012

Labeling in ArcIMS – Avoid Duplicate Labels when there is a JOIN

I came across a scenario where I am supposed to link the GIS features with external tables in ArcIMS. This was a one-to-many relationship, which means for one GIS feature there were many external records.
We want to label this GIS features, but when we tried labeling, it was showing duplicate labels, because of the one-to-many relationship established with the external records.
To control this we used the ArcIMS AXL syntax like shown below.
<SIMPLELABELRENDERER field= "AYED.env_field_sample_loc_point.LOCID" howmanylabels ="one_label_per_shape" labelbufferratio="3.0">
<TEXTSYMBOL antialiasing="true" font="Verdana" fontsize="8" glowing="255,255,255" interval="20"/>
</SIMPLELABELRENDERER>

Note down the tag “
labelbufferratio”. This helps to remove those duplicate labels.
Happy Coding !

Monday, January 30, 2012

Updating ArcGIS FeatureLayer in Silverlight Application after performing a Query

There was a scenario where I need to display a Featurelayer in ArcGIS Silverlight Map Control and when the user performs a search on specific attributes (in this example date values), the Featurelayer records must be refreshed / updated on the Map Control.

The XAML file content is as follows. This featurelayer tag will be inside the MapControl.
<esri:FeatureLayer ID="Your Layer ID" Url="YourURL" Where="1=1" OutFields="All fields required for query seperated by comma." >
</esri:FeatureLayer>

This Button tag when clicked will invoke the Featurelayer Update Action. Note the use of Interaction Triggers.

<Button Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="buttonSearchDates" Content="Search Dates">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click" PreviewInvoke="EventTrigger_PreviewInvoke">
<esri2009:UpdateFeatureLayerAction
FeatureLayerID="Your Layer ID"
TargetName="MapControl" />
</i:EventTrigger>
</i:Interaction.Triggers>

</Button>


Make sure the namespaces are declared properly like this.

xmlns:esri2009="http://schemas.esri.com/arcgis/client/2009"
xmlns:esriBehaviors="clr-namespace:ESRI.ArcGIS.Client.Behaviors;assembly=ESRI.ArcGIS.Client.Behaviors"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"

You also need references to these DLL files. You may need to download Microsoft Expression Blend SDK 4. This coding was done using Silverlight 4.

Microsoft.Expression.Interactions.dll
System.Windows.Interactivity.dll

In the csharp file these are the functions

private void EventTrigger_PreviewInvoke(object sender, System.Windows.Interactivity.PreviewInvokeEventArgs e)
{
PerformQuery(datePickerFrom.SelectedDate.Value, datePickerTo.SelectedDate.Value);
}

private void PerformQuery(DateTime startDate, DateTime endDate)
{
ESRI.ArcGIS.Client.FeatureLayer oFeatureLayer = MapControl.Layers["Your Layer ID"] as ESRI.ArcGIS.Client.FeatureLayer;
if (oFeatureLayer != null)
  {
    string whereClause = GetDateWhereClause(startDate, endDate);
    oFeatureLayer.Where = whereClause;
    oFeatureLayer.Refresh();
   }
}

Hope this will help some programmer.

Cheers
Anand

All Blogs so far ...