Monday, May 10, 2010

HTML 5 postMessage (Cross-Domain Message) on Firefox 3.6.3

This only works in Firefox because IE uses attachEvent(). You can always use dojo.connect( window, 'message', func() ) so it works in Firefox and IE.

A (http://localhost/cross.htm) has an iframe containing B (http://otherdomain/cross.htm)

After the iframe is loaded in A, then a message is sent to it (containing string 'Hello'). The origin is checked in B, and if it matches an alert is displayed.

on A (http://localhost/cross.htm)
<script type="text/javascript">
function iframeload() {
var o = document.getElementById('crossid').contentWindow;
o.postMessage('Hello', "http://otherdomain/cross.htm");
}
</script>

<iframe id="crossid" onload="iframeload();" src="http://otherdomain/cross.htm" width="700px" height="700px">
</iframe>


on B (http://otherdomain/cross.htm)
window.addEventListener('message',function(e) {
if (e.origin == 'http://localhost') {
if (e.data == 'Hello') {
alert(e.data);
e.source.postMessage('Hello');
} else {
alert(e.data);
}
}
}, false);

Friday, May 7, 2010

Javascript for loop + closure

This for loop uses closure to get the value of i for every iteration.
Without closure, every element in divvar will get the last value of x(length-1) from iteration.

for( var i=0;i<divvar.length;i++ ) {
(
function(x) { // -> capture looping variable
divvar[x].onclick = function() {
console.debug("clicked:", x);
}
}
)(i); // -> pass in looping variable
}

Compare this to the standar loop without closure

for( var i=0;i<divvar.length;i++ ) {
divvar[i].onclick = function() {
console.debug("clicked:", i);
};
}

Or we can use dojo.forEach to fix this

Thursday, May 6, 2010

ESRI ArcXML get service info

HTTP POST to http://xxx/IMS/servlet/com.esri.esrimap.Esrimap?ServiceName=six_combo&CustomService=query

ARCXML service info:

<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
<REQUEST>
<GET_SERVICE_INFO fields="false" envelope="false" renderer="false" extensions="true" acetateinfo="false" />
</REQUEST>
</ARCXML>

The response:
<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
<RESPONSE>
<SERVICEINFO>
<ENVIRONMENT>
<LOCALE language="en" country="AU" />
<UIFONT name="Arial" color="0,0,0" size="12" style="regular" />
<SEPARATORS cs=" " ts=";"/>
<CAPABILITIES forbidden="" disabledtypes="" returngeometry="xmlmode"/>
<SCREEN dpi="74"/>
</ENVIRONMENT>
<PROPERTIES>
<FEATURECOORDSYS string="GEOGCS["GCS_GDA_1994",DATUM["D_GDA_1994",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]" id="4283" />
<FILTERCOORDSYS string="GEOGCS["GCS_GDA_1994",DATUM["D_GDA_1994",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]" id="4283" />
<ENVELOPE minx="140.05983881892" miny="-37.740334035" maxx="154.575951211079" maxy="-27.924909045" name="Initial_Extent" />
<ENVELOPE minx="140.05983881892" miny="-37.740334035" maxx="154.575951211079" maxy="-27.924909045" name="Extent_Limit" />
<MAPUNITS units="decimal_degrees" />
<LEGEND/>
</PROPERTIES>
<LAYERINFO type="featureclass" visible="true" name="Suburb Labels" id="Suburb_Label_1" minscale="0.0000308686210057027" maxscale="0.000308686210057027">
<FCLASS type="polygon">
<FIELD name="delivsdm:geodb.Suburb.cadid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.modifieddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.suburbname" type="12" size="40" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.postcode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.state" type="5" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Local Government Area Labels" id="LocalGovernmentArea_Label_1" minscale="0.000246948968045622" maxscale="0.000926058630171081">
<FCLASS type="polygon">
<FIELD name="delivsdm:geodb.LocalGovernmentArea.cadid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.modifieddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.lganame" type="12" size="60" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.councilname" type="12" size="80" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.abscode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.ltocode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.vgcode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.wbcode" type="4" size="10" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="false" name="Locality Labels" id="Locality_Label_1" maxscale="0.0000000308686210057027">
<FCLASS type="point">
<FIELD name="delivsdm:geodb.placepoint.topoid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.objectmoddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.featuremoddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.classsubtype" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.featurereliabilitydate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.attributereliabilitydate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.capturesourcecode" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.capturemethodcode" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.planimetricaccuracy" type="6" size="6" precision="2" />
<FIELD name="delivsdm:geodb.placepoint.verticalaccuracy" type="6" size="6" precision="2" />
<FIELD name="delivsdm:geodb.placepoint.operationalstatus" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.generalnameoid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.generalname" type="12" size="50" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.alternativelabel" type="12" size="50" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.placetype" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.population" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.popsourcedate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.placesignificance" type="5" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
<EXTENSION type="StoredQuery">
<STOREDQUERIES>
<STOREDQUERY name="generalname">
<QUERY subfields="" where="generalname LIKE '[%var%]%'" >
</QUERY>
<SQVAR name="[%var%]" position="0">
<FIELD name="delivsdm:geodb.placepoint.generalname" type="12" />
</SQVAR>
</STOREDQUERY>
</STOREDQUERIES>
</EXTENSION>

</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Road Labels" id="RoadSegment_Label_1">
<FCLASS type="line">
<FIELD name="delivsdm:geodb.RoadSegment.topoid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.objectmoddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.featuremoddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.classsubtype" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.featurereliabilitydate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.attributereliabilitydate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.capturesourcecode" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.capturemethodcode" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.planimetricaccuracy" type="6" size="6" precision="2" />
<FIELD name="delivsdm:geodb.RoadSegment.verticalaccuracy" type="6" size="6" precision="2" />
<FIELD name="delivsdm:geodb.RoadSegment.operationalstatus" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.roadnameoid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.roadnamebase" type="12" size="50" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.roadnametype" type="12" size="20" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.roadnamesuffix" type="12" size="10" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.functionhierarchy" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.roadontype" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.surface" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.lanecount" type="5" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Town Labels" id="Town_Label_1" minscale="0.000246948968045622">
<FCLASS type="point">
<FIELD name="OBJECTID" type="8" size="10" precision="0" />
<FIELD name="NAME" type="12" size="32" precision="0" />
<FIELD name="POSTCODE" type="8" size="10" precision="0" />
<FIELD name="POP_1996" type="8" size="10" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="#ID#" type="-99" size="16" precision="0" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Local Government Area" id="LocalGovernmentArea_1" minscale="0.000246948968045622" maxscale="0.000926058630171081">
<FCLASS type="polygon">
<FIELD name="delivsdm:geodb.LocalGovernmentArea.cadid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.modifieddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.lganame" type="12" size="60" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.councilname" type="12" size="80" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.abscode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.ltocode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.vgcode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.wbcode" type="4" size="10" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Suburbs" id="Suburb_1" minscale="0.0000308686210057027" maxscale="0.000308686210057027">
<FCLASS type="polygon">
<FIELD name="delivsdm:geodb.Suburb.cadid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.modifieddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.suburbname" type="12" size="40" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.postcode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.state" type="5" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Topographic Map Index" id="Topographic_Map_Index_1" maxscale="0.000617372420114054">
<FCLASS type="polygon">
<FIELD name="delivsdm:geodb.topomapindex.mapnumber" type="12" size="10" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.maptitle" type="12" size="32" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.nominalpresentationscale" type="4" size="8" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.mgazone" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.hundredkmapnumber" type="4" size="5" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.presentationformat" type="5" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="NSW Border" id="Border_1" minscale="0.00617372420114054">
<FCLASS type="line">
<FIELD name="IGDS_CLASS" type="4" size="5" precision="0" />
<FIELD name="IGDS_COLOR" type="4" size="5" precision="0" />
<FIELD name="GROUP" type="4" size="5" precision="0" />
<FIELD name="IGDS_STYLE" type="4" size="5" precision="0" />
<FIELD name="WEIGHT" type="4" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="#ID#" type="-99" size="16" precision="0" />
</FCLASS>
</LAYERINFO>

</SERVICEINFO>
</RESPONSE>
</ARCXML>

Thursday, April 29, 2010

ArcGIS Polygon Search

--Polygon Search for Transport Spending
Filter Geometry: {"rings":[[[272276.48887,6179999.947118772],[385469.50589442987,6361478.599097537]]]}
Geometry Type: Polygon
Input Spatial Reference (WKID): 28356
Spatial Relationship: contains
Where clause: empty

I found this by sniffing the traffic of a page that I created by copying and pasting the html in http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jssamples_start.htm#jssamples/util_simplify.html

Monday, April 12, 2010

Installing Erdas Professional 2010 on Amazon EC2

Erdas Professional can only be installed on Windows platform.
1.Basic 64-bit  Microsoft Windows Server 2008 Basic 64-bit Microsoft Windows Server 2008 (AMI Id: ami-cdc22ea4)
2. Download Erdas Apollo Professional 2010 from Erdas website (http://www.erdas.com/Products/ERDASProductInformation/tabid/84/currentid/3148/objectid/3148/default.aspx), you will need to register, and an instruction of how to download it from ftp.erdas.com will be given.
3. Install PostgreSQL (at least 8.3) and PostGIS extension 1.5
4. Create a new database using template_postgis. The username/password/database info will need to be entered into Apollo installation window at some point.
5. Download and install the Erdas net-License Manager (http://www.erdas.com/Products/ERDASProductInformation/tabid/84/currentid/3148/objectid/3148/~/tabid/84/currentid/2491/default.aspx)
6. Request evaluation license from Erdas websites, and follow the instruction of how to install it.
7. Once the license file is installed, you should be able to access http://your-amazon-ec2:8080/apollo-client and http://your-amazon-ec2:8080/erdas-apollo.

Thursday, March 18, 2010

mod_wsgi + apache

mod_wsgi

sudo vim /etc/sysconfig/apache2
sudo /usr/sbin/rcapache2 restart

Monday, March 15, 2010

Netstat + find process Id

Many a times you would get a "Bind Exception", "Address already in use" kind of errors and need to find the process that's using the port. For example say the port is 8080. The following command will get you the pid and program name as well.

netstat -nlept | grep "8080"

The result might look something like this...

Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp6 0 0 :::8080 :::* LISTEN 1000 994652 4024/java
Where 4024 is the pid and it's a java app.