| tukun2009manit wrote: | | tukun2009manit wrote: | i was given a proj. on devlopment of gis application which based on some data can predict the flooding areas of india. to make it more simpler i have to concentrate only on rain and river data. they provide me rain data but i was not having river data. so the problem begins how to enter above 300 entries into database.
a simple solution was to get the data into text file and then by file handling of any programming language the data can be inserted into database.
i used this link to get the lattitude & longitude of the river ganga http://graargh.returnstrue.com/rajdeep/maps/tools/latlong_tool/v7/lat-long-tool_v7.html
then used this code to handel the file:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package filehandel1;
/**
*
* @author Abhijeet
*/
import java.io.*;
import java.sql.*;
public class ReadBytes6 {
public static void main(String args[]) throws IOException, SQLException {
Statement st = null;
ResultSet rs = null;
System.out.println("Checking if Driver is registered with DriverManager.");
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException cnfe) {
System.out.println("Couldn't find the driver!");
System.out.println("Let's print a stack trace, and exit.");
cnfe.printStackTrace();
System.exit(1);
}
System.out.println("Registered the driver ok, so let's make a connection.");
Connection c = null;
try {
// The second and third arguments are the username and password,
// respectively. They should be whatever is necessary to connect
// to the database.
c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test2",
"postgres", "gis12");
} catch (SQLException se) {
System.out.println("Couldn't connect: print out a stack trace and exit.");
se.printStackTrace();
System.exit(1);
}
st = c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
FileInputStream in = new FileInputStream("ganga4.txt");
int b;
int count =224;
boolean toogle = true;
StringBuffer sbr = new StringBuffer();
String str = null;
try {
while ((b = in.read()) != -1) {
sbr.append((char) b);
if (b == 9 || b == (int) '\n') {
str = new String(sbr);
sbr = new StringBuffer();
if (toogle == true) {
System.out.println(toogle + " " + str);
toogle=false;
st.executeUpdate("insert into rivers5(lon) values ("+str+")");
}else{
System.out.println(toogle + " " + str);
toogle=true;
st.executeUpdate("update rivers5 set lat="+str+" where gid="+ ++count);
}
}
}
in.close();
} catch (IOException ioe) {
System.out.println(ioe);
}
if (c != null) {
System.out.println("Hooray! We connected to the database!");
} else {
System.out.println("We should never get here.");
}
}
} |
to get the database entries the following code i used
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package filehandel1;
/**
*
* @author Abhijeet
*/
import java.io.*;
import java.sql.*;
public class ReadBytes8 {
public static void main(String args[]) throws IOException, SQLException {
Statement st = null;
ResultSet rs = null;
Statement st2 = null;
ResultSet rs2 = null;
String str=null;
int len=0;
StringBuffer sbr=new StringBuffer();
System.out.println("Checking if Driver is registered with DriverManager.");
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException cnfe) {
System.out.println("Couldn't find the driver!");
System.out.println("Let's print a stack trace, and exit.");
cnfe.printStackTrace();
System.exit(1);
}
System.out.println("Registered the driver ok, so let's make a connection.");
Connection c = null;
Connection c2 = null;
try {
// The second and third arguments are the username and password,
// respectively. They should be whatever is necessary to connect
// to the database.
c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test2",
"postgres", "gis12");
c2 = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test2",
"postgres", "gis12");
} catch (SQLException se) {
System.out.println("Couldn't connect: print out a stack trace and exit.");
se.printStackTrace();
System.exit(1);
}
st = c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
st2 = c2.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs=st.executeQuery("select * from rivers5");
while(rs.next()){
sbr.append(rs.getDouble(2));
sbr.append(" ");
sbr.append(rs.getDouble(3));
sbr.append(',');
}
len=sbr.length();
sbr.deleteCharAt(len-1);
str=new String(sbr);
System.out.println(str);
st2.executeUpdate("insert into rivers8(name,rivers_geom) values ('ganga',GeomFromText('LINESTRING("+str+")',-1))");
/*FileInputStream in = new FileInputStream("ganga4.txt");
int b;
int count =224;
boolean toogle = true;
StringBuffer sbr = new StringBuffer();
String str = null;
try {
while ((b = in.read()) != -1) {
sbr.append((char) b);
if (b == 9 || b == (int) '\n') {
str = new String(sbr);
sbr = new StringBuffer();
if (toogle == true) {
System.out.println(toogle + " " + str);
toogle=false;
st.executeUpdate("insert into rivers5(lon) values ("+str+")");
}else{
System.out.println(toogle + " " + str);
toogle=true;
st.executeUpdate("update rivers5 set lat="+str+" where gid="+ ++count);
}
}
}
in.close();
} catch (IOException ioe) {
System.out.println(ioe);
}*/
if (c != null) {
System.out.println("Hooray! We connected to the database!");
} else {
System.out.println("We should never get here.");
}
}
} |
1 Saran, Bihar, India 25.741766105738137 84.77806091308594
2 Bihar, India 25.7331067445897 84.65034484863281
3 Bihar, India 25.728776827446488 84.63043212890625
4 Bihar, India 25.661952418647065 84.53842163085938
5 Bihar, India 25.717023400382306 84.44778442382812
6 Bihar, India 25.71516748993636 84.45053100585938
7 Bihar, India 25.755990829182867 84.40589904785156
8 Bihar, India 25.770832202467577 84.38255310058594
9 Bihar, India 25.762793355586624 84.36607360839844
10 Bihar, India 25.741147600865283 84.35783386230469
11 Bihar, India 25.71331155053841 84.33792114257812
12 Bihar, India 25.70588750345636 84.29466247558594
13 Bihar, India 25.70155659545103 84.23011779785156
14 Bihar, India 25.720735134412106 84.19921875
15 Bihar, India 25.72011652011695 84.122314453125
16 Bihar, India 25.692275547735274 84.07768249511719
17 Bihar, India 25.632240651069274 84.03305053710938
18 Buxar, Bihar, India 25.597567576737394 83.99734497070312
19 Buxar, Bihar, India 25.550495180470026 83.91563415527344
20 Buxar, Bihar, India 25.523234285429442 83.902587890625
21 Bihar, India 25.517657429994035 83.84937286376953
22 Bihar, India 25.510531070956958 83.80611419677734
23 Uttar Pradesh, India 25.536245940157283 83.78173828125
24 Ghazipur, Uttar Pradesh, India 25.598496450902395 83.71788024902344
25 Ghazipur, Uttar Pradesh, India 25.610880750315395 83.67084503173828
26 Ghazipur lanka, Uttar Pradesh, India 25.586420524099665 83.60973358154297
27 Ghazipur, Uttar Pradesh, India 25.550185432385575 83.55960845947266
28 Ghazipur, Uttar Pradesh, India 25.483261096987896 83.51531982421875
29 Ghazipur, Uttar Pradesh, India 25.411337882684343 83.5506820678711
30 Ghazipur, Uttar Pradesh, India 25.3970721441564 83.54965209960938
31 Ghazipur, Uttar Pradesh, India 25.392109752773724 83.5400390625
32 Ghazipur, Uttar Pradesh, India 25.395521418766915 83.52149963378906
33 Uttar Pradesh, India 25.48852964248856 83.4085464477539
34 Uttar Pradesh, India 25.49255837439694 83.3807373046875
35 Uttar Pradesh, India 25.47272331328369 83.32855224609375
36 Uttar Pradesh, India 25.517347597093757 83.26160430908203
37 Uttar Pradesh, India 25.532838262237156 83.19568634033203
38 Uttar Pradesh, India 25.493178167318078 83.16547393798828
39 Uttar Pradesh, India 25.4587748268542 83.13526153564453
40 Uttar Pradesh, India 25.434593620577097 83.1441879272461
41 Uttar Pradesh, India 25.419400379899944 83.18195343017578
42 Uttar Pradesh, India 25.3688458240828 83.17611694335938
43 Uttar Pradesh, India 25.326028492609215 83.13629150390625
44 Uttar Pradesh, India 25.33130390989676 83.06694030761719
45 Varanasi, Uttar Pradesh, India 25.313304481678177 83.01921844482422
46 Varanasi, Uttar Pradesh, India 25.301199913769096 83.00994873046875
47 Varanasi, Uttar Pradesh, India 25.274813974793805 83.01681518554688
48 Uttar Pradesh, India 25.243453810607868 83.03054809570312
49 Mirzapur, Uttar Pradesh, India 25.2142598500695 83.01441192626953
50 Mirzapur, Uttar Pradesh, India 25.20649431919982 82.9412841796875
51 Mirzapur, Uttar Pradesh, India 25.198106989381813 82.90695190429688
52 Mirzapur, Uttar Pradesh, India 25.14746010148844 82.88394927978516
53 Mirzapur, Uttar Pradesh, India 25.118553988557046 82.86163330078125
54 Mirzapur, Uttar Pradesh, India 25.111404109921363 82.83451080322266
55 Mirzapur, Uttar Pradesh, India 25.128500949960017 82.77202606201172
56 Mirzapur, Uttar Pradesh, India 25.18288406340071 82.69615173339844
57 Mirzapur, Uttar Pradesh, India 25.227925980729097 82.62611389160156
58 Mirzapur, Uttar Pradesh, India 25.227615403901964 82.5893783569336
59 Mirzapur, Uttar Pradesh, India 25.216744715292 82.56534576416016
60 Mirzapur, Uttar Pradesh, India 25.179155709929145 82.59281158447266
61 Mirzapur, Uttar Pradesh, India 25.16517336866393 82.5900650024414
62 Mirzapur, Uttar Pradesh, India 25.155540156389435 82.56328582763672
63 Mirzapur, Uttar Pradesh, India 25.160512231916684 82.52792358398438
64 Uttar Pradesh, India 25.18288406340071 82.47848510742188
65 Uttar Pradesh, India 25.21891893073226 82.45719909667969
66 Uttar Pradesh, India 25.253701091610008 82.38887786865234
67 Uttar Pradesh, India 25.22854713200372 82.3641586303711
68 Uttar Pradesh, India 25.21519168047479 82.34115600585938
69 Uttar Pradesh, India 25.267052312190323 82.30167388916016
70 Uttar Pradesh, India 25.26829421156167 82.26940155029297
71 Uttar Pradesh, India 25.233205665424844 82.24983215332031
72 Uttar Pradesh, India 25.20494115356912 82.27043151855469
73 Uttar Pradesh, India 25.197796336440597 82.28553771972656
74 Uttar Pradesh, India 25.186301620540558 82.276611328125
75 Uttar Pradesh, India 25.176980784396388 82.23987579345703
76 Uttar Pradesh, India 25.185680253645064 82.20691680908203
77 Uttar Pradesh, India 25.23506902881547 82.20279693603516
78 Uttar Pradesh, India 25.280091621816336 82.2216796875
79 Uttar Pradesh, India 25.303062233688735 82.20691680908203
80 Uttar Pradesh, India 25.312994123248057 82.1725845336914
81 Uttar Pradesh, India 25.278539396522223 82.11868286132812
82 Uttar Pradesh, India 25.272330296765784 82.09636688232422
83 Uttar Pradesh, India 25.290335810632964 82.0785140991211
84 Uttar Pradesh, India 25.32385619514266 82.07542419433594
85 Uttar Pradesh, India 25.350541718482802 82.01946258544922
86 Uttar Pradesh, India 25.339061458818374 81.97345733642578
87 Allahabad, Uttar Pradesh, India 25.424361648676022 81.88522338867188
88 Allahabad, Uttar Pradesh, India 25.425912003292144 81.85741424560547
89 Allahabad, Uttar Pradesh, India 25.413508608042285 81.82273864746094 |