Thursday, July 16, 2015
address to coordinates transformation through openstreetmap
http://nominatim.openstreetmap.org/search/gb/birmingham/pilkington%20avenue/135?format=xml&polygon=1&addressdetails=1
Search through the above url and the response is in xml format.
I have written a java app to convert address to coordinates
here is my code:
package javaconnection;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class JavaConnection
{
public static void main(String[] args) throws MalformedURLException, IOException, SAXException, ParserConfigurationException, Exception
{
String roadnumber = "135";
String AvenuneName = "pilkington";
String avenue = "avenue";
String Country = "birmingham";
String BaseURL = "http://nominatim.openstreetmap.org/search/";
String uri =
BaseURL + roadnumber + "%20" + AvenuneName + "%20"
+ avenue + "," + "%20" + Country
+ "?format=xml&point=1&addressdetails=1";
URL url = new URL(uri);
HttpURLConnection connection =
(HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "application/xml");
InputStream xml = connection.getInputStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(xml);
prettyPrint(doc);
}
public static final void prettyPrint(Document xml) throws Exception
{
Transformer tf = TransformerFactory.newInstance().newTransformer();
tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
tf.setOutputProperty(OutputKeys.INDENT, "yes");
Writer out = new StringWriter();
tf.transform(new DOMSource(xml), new StreamResult(out));
for (String coordinates : out.toString().split(" "))
{
if(coordinates.contains("lon="))
System.out.println(coordinates);
if(coordinates.contains("lat="))
System.out.println(coordinates);
}
// System.out.println(out.toString());
}
}
Thursday, March 11, 2010
a question about stack
in class we learned how S.pop() delete data in stack. My question is that whether we should delete data in reverse order?
S.push(Student("Fardad", "oop344", 56));
S.push(Student("John", "int322", 100));
S.push(Student("Jack", "int422", 90));
S.pop();
S.pop();
while(!S.IsEmpty()){
cout< }
Student StdStack::pop(){
Student ret = top->data;
Node* ToDel = top;
top = top->next;
delete ToDel;
return ret;
}
the output is Fardad, oop344: 56
i read some material in btp300
Element pop() {
Element data;
if (head) {
Node* p = head;
data = head->data;
head = head->next;
delete p;
}
return data;
}
Stack s;
// Push Data Onto Stack
s.push(3);
s.push(5);
s.push(9);
s.push(8);
// Remove first Node
s.pop();
// Pop Data Off Stack
while (!s.empty())
cout << s.pop().out() << ' ';
cout << endl;
the output is 9 5 3
could any one explain the difference between this two example why the pop() are different?
S.push(Student("Fardad", "oop344", 56));
S.push(Student("John", "int322", 100));
S.push(Student("Jack", "int422", 90));
S.pop();
S.pop();
while(!S.IsEmpty()){
cout<
Student StdStack::pop(){
Student ret = top->data;
Node* ToDel = top;
top = top->next;
delete ToDel;
return ret;
}
the output is Fardad, oop344: 56
i read some material in btp300
Element pop() {
Element data;
if (head) {
Node* p = head;
data = head->data;
head = head->next;
delete p;
}
return data;
}
Stack s;
// Push Data Onto Stack
s.push(3);
s.push(5);
s.push(9);
s.push(8);
// Remove first Node
s.pop();
// Pop Data Off Stack
while (!s.empty())
cout << s.pop().out() << ' ';
cout << endl;
the output is 9 5 3
could any one explain the difference between this two example why the pop() are different?
Monday, February 22, 2010
need help for tab_key
i find that when you insert '\t' in a string. it inserts 4 ' ' forward. But we write the bio library we can not control cursor to pass '\t' character.So can anyone teach me how to move cursor to pass '\t'?
Sunday, February 14, 2010
reiview for pointer and pointer to function
different type of pointer.
a) int a; // An integer
b) int *a; // A pointer to an integer
c) int **a; // A pointer to a pointer to an integer
d) int a[10]; // An array of 10 integers
e) int *a[10]; // An array of 10 pointers to integers
f) int (*a)[10]; // A pointer to an array of 10 integers
g) int (*a)(int); // A pointer to a function a that takes an integer argument and returns an integer
h) int (*a[10])(int); // An array of 10 pointers to functions that take an integer argument and return an integer
a) int a; // An integer
b) int *a; // A pointer to an integer
c) int **a; // A pointer to a pointer to an integer
d) int a[10]; // An array of 10 integers
e) int *a[10]; // An array of 10 pointers to integers
f) int (*a)[10]; // A pointer to an array of 10 integers
g) int (*a)(int); // A pointer to a function a that takes an integer argument and returns an integer
h) int (*a[10])(int); // An array of 10 pointers to functions that take an integer argument and return an integer
Monday, February 1, 2010
pointer arithmentic
a[99]={.....}
short int* p = a;
short int** q = &p;
p++;//this means that pointer position increase one so that a[0] become a[1]
(*p)++;//this means that the value the pointer is pointing to increase one.
(*q)++;//means pointer p add 1 position so a[1] move to a[2]
(**q)++//means value of pointer q pointing to add one so the value the pointer p point to add 1
short int* p = a;
short int** q = &p;
p++;//this means that pointer position increase one so that a[0] become a[1]
(*p)++;//this means that the value the pointer is pointing to increase one.
(*q)++;//means pointer p add 1 position so a[1] move to a[2]
(**q)++//means value of pointer q pointing to add one so the value the pointer p point to add 1
Sunday, January 24, 2010
svn command on linux
1.svn --help
List Subversion commands
2.svn help command Also: ? or h
Help on given "command"
3.svn add filename
svn add directory
Add a file or directory to Subversion CM control.
Must also perform: svn ci filename (or svn commit) to upload the file or directory. File will not be available in the repository until a "commit" is performed. If adding a directory, the directory and all of its contents recursively are added. i.e.:
svn ci directory
svn commit directory
svn commit .
4.svn cleanup
Cleanup subversion files resulting from escaped processes and crashed.
5.svn commit filename
svn commit --message "Message goes here." filename
svn commit -m "Message goes here." filename
svn ci filename1 filename2 filename3
svn ci .
Check-in (commit) local "working" file, files or directory and contents (recursively) into Subversion repository. Atomic, i.e. all committed or none, no incomplete check-in.
6.svn diff filename
svn di filename
Show file diffs between SVN repository and your file changes using GNU file diff format. Use GUI diff tools as shown below.
List Subversion commands
2.svn help command Also: ? or h
Help on given "command"
3.svn add filename
svn add directory
Add a file or directory to Subversion CM control.
Must also perform: svn ci filename (or svn commit) to upload the file or directory. File will not be available in the repository until a "commit" is performed. If adding a directory, the directory and all of its contents recursively are added. i.e.:
svn ci directory
svn commit directory
svn commit .
4.svn cleanup
Cleanup subversion files resulting from escaped processes and crashed.
5.svn commit filename
svn commit --message "Message goes here." filename
svn commit -m "Message goes here." filename
svn ci filename1 filename2 filename3
svn ci .
Check-in (commit) local "working" file, files or directory and contents (recursively) into Subversion repository. Atomic, i.e. all committed or none, no incomplete check-in.
6.svn diff filename
svn di filename
Show file diffs between SVN repository and your file changes using GNU file diff format. Use GUI diff tools as shown below.
Saturday, January 16, 2010
Review for previous class
Prefix increment vs Postfix increment
int main(){
int a=0;
int b=0;
int c=0;
c = a++ + 36;//c will be 36 a will be 1. a is 0 and when this operation finish a get //added
printf("%d",c);
}
int main(){
int a=0;
int b=0;
int c=0;
c = ++a + 36;//c will be 37 a will be 1. before operation a get added and affect //result
printf("%d",c);
}
int main(){
int a=0;
int b=0;
int c=0;
c = a++ + 36;//c will be 36 a will be 1. a is 0 and when this operation finish a get //added
printf("%d",c);
}
int main(){
int a=0;
int b=0;
int c=0;
c = ++a + 36;//c will be 37 a will be 1. before operation a get added and affect //result
printf("%d",c);
}
Subscribe to:
Posts (Atom)