Tehrik-e-Insaaf

Earn 600$ by Clicking on each Ad

GoWellUp.com

Thursday, March 5, 2009

Geography Markup Language

The Geography Markup Language (GML) is the XML grammar defined by the Open Geospatial Consortium (OGC) to express geographical features. GML serves as a modeling language for geographic systems as well as an open interchange format for geographic transactions on the Internet. Note that the concept of feature in GML is a very general one and includes not only conventional "vector" or discrete objects, but also coverages (see also GMLJP2) and sensor data. The ability to integrate all forms of geographic information is key to the utility of GML.

GML Model

The original GML model was based on the World Wide Web Consortium's Resource Description Framework (RDF). Subsequently, the OGC introduced XML schemas into GML's structure to help connect the various existing geographic databases, whose relational structure XML schemas more easily define. The resulting XML-schema-based GML retains many features of RDF, including the idea of child elements as properties of the parent object (RDFS) and the use of remote property references.

GML contains a rich set of primitives which are used to build application specific schemas or application languages. These primitives include:

Monday, March 2, 2009

POSTGIS

POSTGIS
What is POSTGIS

PostGIS is an extension for PostgreSQL RDBMS that spatially enables it for storing GIS content.

It could be considered something similiar to Esri ArcSDE or Oracle Spatial.
In fact PostGIS is for PostgreSQL what is Esri ArcSDE for Oracle, MS SQL Server, Informix, DB2.

PostGIS is OGC compliant and is Open Source, released under the GNU General Public License.

For more info about PostGIS you can take a look here.

Create POSTGIS Database

First create the PostgreSQL database, using PostgreSQL in the command window or the pgAdmin III SQL window, typing:

CREATE DATABASE "TUTORIAL"
WITH OWNER = psqluser
ENCODING = 'UTF8'
TABLESPACE = pg_default;

After creating the database you have to enable it for storing, with PostGIS, the geographic information.
For doing so you have to enable PL/pgSQL procedural language extension.

You have to use the createlang command (under Windows use the command prompt, under the PostgreSQL’s bin folder):

createlang plpgsql -U psqluser -D TUTORIAL

Now you can succesfully load the PostGIS objects and functions by the lwpostgis.sql script.

psql -U psqluser -d TUTORIAL -f lwpostgis.sql

After doing so, you can see that a lot of object and functions are now loaded in TUTORIAL database.

This objects and functions are necessary for PostGIS to work.


Load Data In POSTGIS

There are several ways in order to load geometry objects in PostGIS.

It is possible to load data using SQL, or using the Loader utility (shp2pgsql command, similiar to the shp2sde command for ArcSDE). In fact the loader utility is a command that will generate the SQL with the INSERT statment to load geometries in PostGIS.

Let’s see this two ways.

1. Load Data In POSTGIS Using SQL

Create a table named TEST:

BEGIN;
CREATE TABLE "test" ("id" int4, "name" varchar(20));
SELECT AddGeometryColumn('','test','the_geom', '-1', 'LINESTRING',2);
END;

Let’s load the first linestring gis object in this table, using the GeomFromText function:

INSERT INTO "test" ("id","name","the_geom") VALUES (1, 'First Geometry', GeomFromText('LINESTRING(1 1,2 2,3 3,3 4)'));

Let’s retrieve this GIS object with the database:

SELECT id, name, the_geom FROM TEST;

> 1;"First Geometry";"01020000..."

As we can notice, the geometry information with a simple SELECT statment is retrieved as is stored in PostGIS database: as a binary string.

If we wan’t to retrieve the geometry information as a simple Open GIS Well Known Text Format string, we can use another function that was created in the TUTORIAL database by the lwpostgis.sql script: AsText

SELECT id, name, AsText(the_geom) FROM TEST;

> 1;"First Geometry";"LINESTRING(1 1,2 2,3 3,3 4)"

2. Load data (shapefiles) in PostGIS using the shp2pgsql command

To load shapefiles in PostGIS database you can use the Loader utility: the shp2pgsql command (under bin’s folder). This utility simply creates from any shapefile an sql file that can be used in PostGIS to load the shapefile in the database.

We will now load the tutorial’s shapefiles (compfun.shp, poi.shp, vestizioni.shp, zone.shp) into the TUTORIAL database we created with PostGIS.

First we will use the shp2pgsql command to produce the sql files:

shp2pgsql C:\training\mapServerTutorial\data\poi.shp poi > C:\training\mapServerTutorial\data\poi.sql
shp2pgsql C:\training\mapServerTutorial\data\compfun.shp compfun > C:\training\mapServerTutorial\data\compfun.sql
shp2pgsql C:\training\mapServerTutorial\data\vestizioni.shp vestizioni > C:\training\mapServerTutorial\data\vestizioni.sql
shp2pgsql C:\training\mapServerTutorial\data\zone.shp zone > C:\training\mapServerTutorial\data\zone.sql

Now we can use the 4 sql files produced with PostGIS: these sql files will phisically load the shapefile geometries in 4 PostGIS tables.

Executing the poi.sql script will create in TUTORIAL database the poi table:

BEGIN;
CREATE TABLE "poi" (gid serial PRIMARY KEY, "poi_time" varchar, "poi_user" varchar);
SELECT AddGeometryColumn('','poi','the_geom','-1','POINT',2);
INSERT INTO "poi" ("poi_time","poi_user",the_geom) VALUES ('04/08/2006, 16.23.41','Paolo','0101000000713D0A170A7A3141B81E853B33DB5041');
INSERT INTO "poi" ("poi_time","poi_user",the_geom) VALUES ('04/08/2006, 16.24.09','Paolo','01010000005C8FC2D5FB79314152B81E9971DB5041');
END;

Executing the compfun.sql script will create in TUTORIAL database the compfun table:

BEGIN;
CREATE TABLE "compfun" (gid serial PRIMARY KEY, "objectid" int8, "codarea" int8, "shape_area" numeric, "shape_len" numeric);
SELECT AddGeometryColumn('','compfun','the_geom','-1','MULTIPOLYGON',2);
INSERT INTO "compfun" ("objectid","codarea","shape_area","shape_len",the_geom) VALUES ('4052','2801','3.45349032455e+006','8.16732468815e+003','0106000000010000000103000000010000001D00000040996FAA397B3141E07CD98012DC50414016BF4B637B314120EDD71DF2DB5041C0C48863797C3141C026D7070CDC5041C08D9B964B7D3141C040084D8DDB504100750AE32F7B3141102BE15F19DB5041809E6B9AC87A3141906226D602DB504180B38C4A967931410077244BC0DA504100CCFE59B177314160708AEE51DA504180DD9DBA9F76314100C6939B17DA5041C04FAAF651763141706CA3D154DA504140EF3C1B8E7531411049C4A0EFDA5041003A43365D753141004DABBDECDA5041000172392C753141B0E26CBB34DB5041C080CC767F743141F057440D93DB5041402243CBBE74314110CE02459ADB5041003E9495AA743141603B417EA6DB5041C04DC6C64E753141E05D04A8BADB5041402243CBBE7431416060D6F125DC5041C080CC767F743141C0C546F137DC5041809068EA7374314150E422FE4EDC5041805FFBE4EC743141B00EB4615DDC5041403275FC62753141F05CE8A069DC504100C2B632047631414029A95177DC504140BA7EB6B97631419096E78A83DC5041C094C6072A773141C0A93C2E8CDC50410017E6B7897931416003F8D6A6DC504100DC11CE5E7A3141A0551333B0DC5041C0B399BBFB7A3141D0664F850DDC504140996FAA397B3141E07CD98012DC5041');
END;

Executing the vestizioni.sql script will create in TUTORIAL database the vestizioni table:

BEGIN;
CREATE TABLE "vestizioni" (gid serial PRIMARY KEY, "objectid" int8, "codarea" int8, "classe" int4, "tipo" int4, "cod" int4, "origine" int4, "shape_len" numeric);
SELECT AddGeometryColumn('','vestizioni','the_geom','-1','MULTILINESTRING',2);
INSERT INTO "vestizioni" ("objectid","codarea","classe","tipo","cod","origine","shape_len",the_geom) VALUES ('89833','2801','8','1','801','2','2.14449030864e+001','010500000001000000010200000002000000403738813D7C3141A08D27B907DC5041800BC76B457C314190779DBD02DC5041');
INSERT INTO "vestizioni" ("objectid","codarea","classe","tipo","cod","origine","shape_len",the_geom) VALUES ('89834','2801','8','1','801','2','5.51685811591e+000','01050000000100000001020000000200000040DFB2743B7C3141B0E4FA0009DC5041403738813D7C3141A08D27B907DC5041');
INSERT INTO "vestizioni" ("objectid","codarea","classe","tipo","cod","origine","shape_len",the_geom) VALUES ('89835','2801','8','1','801','2','9.23513291375e+000','01050000000100000001020000000200000040CB8C02387C3141C0C057250BDC504140DFB2743B7C3141B0E4FA0009DC5041');
/*
other omitted INSERT statments...
*/

END;

Executing the zone.sql script will create in TUTORIAL database the zone table:

BEGIN;
CREATE TABLE "zone" (gid serial PRIMARY KEY, "objectid" int8, "codarea" int8, "classe" int4, "tipo" int4, "cod" int4, "numlott" int8, "lottoid" numeric, "shape_area" numeric, "shape_len" numeric);
SELECT AddGeometryColumn('','zone','the_geom','-1','MULTIPOLYGON',2);
INSERT INTO "zone" ("objectid","codarea","classe","tipo","cod","numlott","lottoid","shape_area","shape_len",the_geom) VALUES ('46929','2801','1','7','107','117','2.80111700000e+006','5.68543477776e+003','3.01854931948e+002','0106000000010000000103000000010000000700000040900304607A3141900DF7EA83DB5041C0D4C76B7C7A3141205BC65C72DB5041C0E425CB7C7A314120791E9271DB5041C0E80CE8797A3141201B4EDF70DB5041803FC859407A3141F018096069DB5041C07A13F7207A314160903B487DDB504140900304607A3141900DF7EA83DB5041');
INSERT INTO "zone" ("objectid","codarea","classe","tipo","cod","numlott","lottoid","shape_area","shape_len",the_geom) VALUES ('46935','2801','1','7','107','110','2.80111000000e+006','6.65516688758e+003','3.94268253922e+002','01060000000100000001030000000100000007000000008FFB54307A314140C89894A1DB504180AF5AF5427A314100B92A0E96DB5041408C671FB9793141B0F4188D88DB50410008CE1BAD793141E063DA5990DB5041C03447E0D4793141F070036194DB5041C0C0EC31CF7931411030BA1498DB5041008FFB54307A314140C89894A1DB5041');
INSERT INTO "zone" ("objectid","codarea","classe","tipo","cod","numlott","lottoid","shape_area","shape_len",the_geom) VALUES ('46937','2801','1','7','107','116','2.80111600000e+006','7.15624610182e+003','3.39270025503e+002','01060000000100000001030000000100000005000000C07A13F7207A314160903B487DDB5041803FC859407A3141F018096069DB5041C02DDE73F8793141C0A7E30960DB50410009F5D4D679314140E3658775DB5041C07A13F7207A314160903B487DDB5041');
/*
other omitted INSERT statments...
*/

END;

Sunday, January 18, 2009

Interview Questions For GIS

1. GIS is a highly technical, cutting edge technology. As a member of the IT community, how do you stay current with changes in GIS and technology?


2. You have been given a text file consisting of miscellaneous data including names, addresses, and X-Y coordinates. How would you input this data into a GIS?

3. What is the difference between CAD and GIS? What would an appropriate use be for either?

4. What is a projection? How is a projection changed using ARCINFO or ArcView?

5. How do raster and vector data differ, and give an example of each?

6. How would you copy a file from a network location in a Windows environment?

7. What is Heads-Up Digitizing?

8. What is a variable?

9. What is the difference between a Union and an Intersect function?

10. Given a database with a “Last Name” Field, describe a SQL statement that selects all people with the last name of Smith.

11. What file is required to properly display a TIFF Image in the correct coordinate space?

12. Given a Future Land Use coverage or shapefile, how could you calculate the acreages by Land Use type? Assume that there is a field called “acreage.”

13. A data request for eagle nest locations has been given to you. How do you go about locating the data?

14. How do you set an environment variable in Windows NT, 9x or any programming language?

Thursday, November 6, 2008

Oracle Spatial Queries



Table Creation in Oracle Spatial (DDL Command)

CREATE TABLE mylake ( feature_id NUMBER PRIMARY KEY, name VARCHAR2(32),
shape MDSYS.SDO_GEOMETRY);


Insert (DML Command) in Oracle Spatial

INSERT INTO mylake VALUES( 10, -- feature_id 'Lake Calhoun', -- name MDSYS.SDO_GEOMETRY(2003,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1, 19,2003,1),MDSYS.SDO_ORDINATE_ARRAY(0,0, 10,0, 10,10, 0,10, 0,0, 4,4, 6,4, 6,6, 4,6, 4,4)
));


Querying

SELECT name boat_nameFROM mylake tWHERE feature_id = 12AND SDO_FILTER(t.shape, mdsys.sdo_geometry(2003,NULL,NULL, mdsys.sdo_elem_info_array(1,1003,1), mdsys.sdo_ordinate_array(2,2, 5,2, 5,5, 2,5, 2,2)),
'querytype=WINDOW') = 'TRUE';


This query selects all boats that have geometry with an indexed grid square within the polygon defined. This doesn't necessarily mean the returned boats are within the rectangle or if they are just touching the defined rectangle. To obtain an exact query, a second function called SDO_RELATE must be executed. SDO_RELATE looks at two geometries and determines if they interact in a specified way. It is important to note that SDO_RELATE only works on two-dimensional data. It is defined below.

SDO_RELATE(geometry1 MDSYS.SDO_GEOMETRY, geometry2 MDSYS.SDO_GEOMETRY, params VARCHAR2)

SDO_RELATE arguments are the same as those for SDO_FILTER with the exception of the last argument. The params argument has a masktype value in addition to the querytype value. The masktype value can take the values listed below.

  • DISJOINT — the boundaries and interiors do not intersect
  • TOUCH — the boundaries intersect but the interiors do not intersect
  • OVERLAPBDYDISJOINT — the interior of one object intersects the boundary and interior of the other object, but the two boundaries do not intersect. This relationship occurs, for example, when a line originates outside a polygon and ends inside that polygon.
  • OVERLAPBDYINTERSECT — the boundaries and interiors of the two objects intersect
  • EQUAL — the two objects have the same boundary and interior
  • CONTAINS — the interior and boundary of one object is completely contained in the interior of the other object
  • COVERS — the interior of one object is completely contained in the interior of the other object and their boundaries intersect
  • INSIDE — the opposite of CONTAINS. A INSIDE B implies B CONTAINS A.
  • COVEREDBY — the opposite of COVERS. A COVEREDBY B implies B COVERS A.
  • ON — the interior and boundary of one object is on the boundary of the other object (and the second object covers the first object). This relationship occurs, for example, when a line is on the boundary of a polygon.
  • ANYINTERACT — the objects are non-disjoint.
To select all boats that are inside a defined rectangle the following query would work:

SELECT name boat_nameFROM mylake tWHERE feature_id = 12AND SDO_FILTER(t.shape, mdsys.sdo_geometry(2003,NULL,NULL, mdsys.sdo_elem_info_array(1,1003,1), mdsys.sdo_ordinate_array(2,2, 5,2, 5,5, 2,5, 2,2)), 'querytype=WINDOW') = 'TRUE'AND SDO_RELATE(t.shape, mdsys.sdo_geometry(2003,NULL,NULL, mdsys.sdo_elem_info_array(1,1003,1), mdsys.sdo_ordinate_array(2,2, 5,2, 5,5, 2,5, 2,2)), 'masktype=INSIDE querytype=WINDOW') = 'TRUE'

It is also possible to combine masktypes to select sites that are inside or touching the defined polygon with the query below.

SELECT feature_id idFROM mylake tWHERE feature_id = 12AND SDO_FILTER(t.shape, mdsys.sdo_geometry(2003,NULL,NULL, mdsys.sdo_elem_info_array(1,1003,1), mdsys.sdo_ordinate_array(2,2, 5,2, 5,5, 2,5, 2,2)), 'querytype=WINDOW') = 'TRUE'AND SDO_RELATE(t.shape, mdsys.sdo_geometry(2003,NULL,NULL, mdsys.sdo_elem_info_array(1,1003,1), mdsys.sdo_ordinate_array(2,2, 5,2, 5,5, 2,5, 2,2)), 'masktype=INSIDE+TOUCH querytype=WINDOW') = 'TRUE'

Wednesday, October 22, 2008

How to change the default form in windows application in c#.net

Go to Program.cs of your application and replace the form name with your form name in Application.Run

Example

Application.Run(new MainForm());

How to fill the datagrid with the data from database using datasets

1. Make connection String and selection statement
SqlConnection conn = new SqlConnection(@"Data Source=192.125.5.1;Initial Catalog=Test;User ID=sa;Password=sa;");
string getCommand = @"select * from dbo.compDetails";

2. Declare the object of command & give the respective parameters
//give selection statement
SqlCommand cmd = new SqlCommand(getCommand);
//give the command type
cmd.CommandType = CommandType.Text;
//give connection object
cmd.Connection = conn;

3. Declare the object of SqlDataAdpater & give command object
SqlDataAdapter da = new SqlDataAdapter(cmd);

4. Declare the object of dataset as container of data
DataSet ds = new DataSet();

5. Open the connection
conn.Open();

6. Fill the object of data Adapter with dataset object
da.Fill(ds, "dbo.complaints");

7. Provide the dataset object as a source to dataGrid
this.dataGrid1.DataSource = ds.Tables[0];

8. Close the connection
conn.Close();


Example:

public void getData()
{
SqlConnection conn = new SqlConnection(@"Data Source=192.125.5.1;Initial Catalog=Test;User ID=lrmis;Password=lrmis;");
string getCommand = @"select * from dbo.compDetails";
SqlCommand cmd = new SqlCommand(getCommand);
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
conn.Open();
da.Fill(ds, "dbo.complaints");
this.dataGrid1.DataSource = ds.Tables[0];
conn.Close();
}

How to Insert Data in Database in c#

1. First of all make connection string
string connString="Data Source=databasename;Initial Catalog=Test;User ID=sa;Password=sa;"
SqlConnection conn = new SqlConnection(connString);

2. Open the connection
conn.Open();

3. Write the insert command
string insertCommand= @"insert into dbo.compDetails(OwnerId, compName, compAddress, compPhone) values('" + compId + "','" + this.txtCompaName.Text + "','" + this.txtCompAddress.Text + "','" + this.txtCompPhone.Text + "')";

SqlCommand cmdInsert = new SqlCommand(insertCommand, conn);

4. Execute the command
cmdInsert.ExecuteScalar();

5. Close the connection
conn.Close();


Example:

public void setData()
{

string connString="Data Source=databasename;Initial Catalog=Test;User ID=sa;Password=sa;"
SqlConnection conn = new SqlConnection(connString);
conn.Open();
Guid compId = Guid.NewGuid();
string insertCommand= @"insert into dbo.compDetails(OwnerId, compName, compAddress, compPhone) values('" + compId + "','" + this.txtCompaName.Text + "','" + this.txtCompAddress.Text + "','" + this.txtCompPhone.Text + "')";
SqlCommand cmdInsert = new SqlCommand(insertCommand, conn);
cmdInsert.ExecuteScalar();
conn.Close();

}