Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Using database to store map information, rather than shape file

The ultimate goal is to be more flexible in design, display, and modify tabular data.

Solution:
1. Using the MySQL server
2. Using PostGIS on PostgreSQL server


Which is recomended to use PostGIS in PostgreSQL with the following reasons:
1. Already available template spatial database and its functions, geometry, geography, etc..
2. Already available importers of shape files to PostGIS data.
 


In Map File, data connection that from shapefile should be changed to PostGIS with syntax as follows: 

CONNECTIONTYPE POSTGIS
CONNECTION "host=localhost port=5432 
dbname=db_name user=user_name password=_password" 
PROCESSING "CLOSE_CONNECTION=DEFER" 
DATA "geom FROM table_name using unique gid using srid=4326" 

Please note that the "DATA" in connection above is using geom field as the geometry field. You can use with your own field, as long as the data type is geometry.

As well, the "srid=4326" is EPSG code that represent the UTM zone. Currently, we use this as "default" :) , because so far we still don't understand what is it.

If you want to know about PostGIS, please visit http://www.gdal.org/ogr/drv_pg.html  and http://postgis.refractions.net/documentation/manual-1.4/ch01.html. Generally, It is mandatory to know about PostgreSQL (http://www.postgresql.org/) further more.

Thanks,
Danan

Map File Maker

Map file is one of the main files required by the map server. This file contains a map of how it will be displayed, including information on the color, font, projection, etc..
The need for the appearance of the map is varied and complex requires the creation of this file can be generated automatically from the shape file.

Using Quantum GIS to save map as map file, with the following steps :
1. Open Shape file
2. Edit any information, include legend attribute, color, word text, label, symbology, etc.
3. Save as qgs file.
4. Save as map file
5. Edit map file to fulfill any other setting needed, such as path img file.
6. Done, map file is ready to used
Thanks,
Danan

ASP.net Navigation menu component on chrome

Chrome add an extra space above the asp.net navigation. This will cause any other sizing appear incorrectly.
ASP.net navigation menu created space with the following tags - before navigation div:

There are 2 solution :
1. We can set as display none for them using the following style :

2. But using display none is not recomended since we still don't know why asp.net create the space. Instead, we can use the following style :


It works fine now, without any extra space on chrome.
Thanks,
Danan

Too long path problem

There is a weird issue, that .net only support for 260 character file path. Resolved it by using ZetaLongPath .net library :
  1. Download ZetaLongPath library at http://zetalongpaths.codeplex.com/releases/view/103680
  2. Add the dll file into references
  3. Just use it similar with FileInfo library
Thanks,

Solr Indexing Memory

Increase the memory needed to index the large file. Resolved by increasing java virtual machine memory, as follows :
java -Xms512M -Xmx1024M -jar start.jar

Get JSON Data

JSON (JavaScript Object Notation) is a lightweight data-interchange format. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others (http://www.json.org/)

How to get those data and deserialize them into our object data ?
You can check out the following C# code :
Please note that Track object properties should be configured as same as the JSON return value. As such, before create the object data, you must generate c# classes from JSON. You may use jsonTocsharp by simply entering the JSON, and klik generate, you will get a bunch properties that should be put within your class/object.

For further knowledge about JSON, you can visit Mastering JSON

May it helps,
Thanks

Google Maps API - Example

Simple example how to put map into our website :
  1. Call google maps javascript API :
  2. Put this javascript :
  3. Type this in your body tag :
  4. Type this under head tag, to set css style (optional) :

For complete tutorial and reference, please read Google Map Javascript API Tutorial and Google Map Javascript API Reference

May it helps,
Thanks 

Solr File Indexing

Solr also support for file indexing, such as content, author, and any meta data inside a file.
I will show you how to use this, with assume that the solrconfig.xml is already set up as my environment.
Check out below :
  1. Call URL address directly from browser (or using curl command), as follow :
  2. OR, you can call via WebClient object in C# on ASP.Net : The content is not indexed, but recorded, just to minimize the memory use.

For complete reference, please read Solr Wiki - ExtractingRequestHandler
My it helps,
Thanks

Faceted Search using Solr

How to use Solr faceted search :
  1. To understand and how to install, please read Apache Solr
  2. To using within .net, please read and download Solr client for .NET
  3. This is how solr first initialization. Put this code inside application_start within your Global.asax file
  4. This is how solr and solr.net related with your class data object
  5. To add to index, code shown as below
  6. To retrieve the data, based on faceted search by user
Please note :
  • Language : C# on ASP.Net
  • Library needed : Solrnet, Castle Windsor, and WindsorAdapter

May it helps,
Thanks

NHibernate – How to use

An example, how to use Nhibernate :
  1. Add code below to your web.config file 
  2. Create session manager class as below 
  3. Call them with this code 
  4. And use them as needed, to save or delete 
Please also note below :
  • Language : C# on ASP.Net 
  • Database  : MySQL 
  • Library needed : Nhibernate, Castle Windsor, WindsorAdapter

May it helps, Thanks

Currency Converter using Google API

Google API provides currency conversion rates.
For example, to convert 1 USD into Indonesian Rupiah (IDR), you can call Google API with the following format :
http://www.google.com/ig/calculator?hl=en&q=1USD=?IDR

URL above will return JSON objects below :
{lhs: "1 U.S. dollar",rhs: "9 523.80952 Indonesian rupiahs",error: "",icc: true}

The following code is an example how to get the value as a final result of the convertion :

public bool Convert(string baseCurrency, string targetCurrency, out double currencyRate)
        {
            try
            {
                string url = string.Format("http://www.google.com/ig/calculator?hl=en&q=1{0}%3D%3F{1}",  baseCurrency, targetCurrency);
                WebClient web = new WebClient();
                web.Encoding = System.Text.Encoding.ASCII;
                string response = web.DownloadString(url);
                Regex regex = new Regex("rhs: \\\"(\\d*.\\d*.\\d*)");
                Match match = regex.Match(response);
                string sRate = match.Groups[1].Value.ToString();
                sRate = sRate.Replace("?", "");
                currencyRate = System.Convert.ToDouble(sRate);
                currencyRate = Math.Round(currencyRate, 2);
            }
            catch(Exception)
            {
                currencyRate = 0;
                return false;
            }

            return true;
           
        }



Reference are System.Text.RegularExpressions, System.Net.WebClient, and System.Math.

Ok, may it helps,

Thanks

MySQL Federated table

Federated table in MySQL is just like a link table in Microsoft SQL Server. It imports the table structure and data from any other server or database, and also synchronize the data as well.

To Enable the federated storage,note the following step :
1. Stop your currently running MySQL service
2. From Command Prompt, run the mysqld.exe with the parameter –federated (mysqld.exe –federated).
3. You can close the command-window above.
4. Start your service again, you now have federated storage engine enabled, check with SHOW ENGINES \G.
5. Go to C:\Program Files\MySQL\MySQL Server 5.0
6. Open the file my.ini. Just put federated after [mysqld] and save the file.
7. Restart MySQL server and type command SHOW ENGINES \G .
8. You will see a value  'YES' in Support column for engine FEDERATED.

Below is the example how to create a federated table :
Let say, we have a "my_aspnet_Users" table at server 192.168.30.19 with database name "test".
So, now we want to create the link table that linked to table above.
We can type and execute the following sql script :

Done ... and check on your database, it has a new federated table.

Okay,
Hope this helps

Get the Field Name from a Class Data

How to Get the list of fields from a class, let say "ProposalData".
ProposalData contains public property Id, Title, and SubmissionDate. We will get those three property using System.Reflection member class called "PropertyInfo". See the example below:

public List<string> GetFieldProposalDataData()
{
List<string>listField = new List<string>();
PropertyInfo[] propertyInfos;
propertyInfos = typeof(ProposalData).GetProperties();
foreach (PropertyInfo propertyInfo in propertyInfos)
{
listField.Add(propertyInfo.Name);
}
return listField;
}

Okay, may it helps

Thread was being aborted

Such title above, is caused by Page Redirect inside try and catch methods.
That, could be solved by adding "false" parameter inside :

Response.Redirect("Page.aspx",false);

Okay, may it helps

Multiple database on Nhibernate

Multiple database is supported by Nhibernate.
Example below is using schema tag (bold) on hbm.xml file :


<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" schema="worktracking">




Schema means = Database name
But, this method only work on the same server.

Okay, may it helps

AutoComplete using JQuery

Here are step by step to implement Jquery Auto Complete :

1. Download the files

2. Add this script into your page:

 <script src="<%= ResolveClientUrl("~/js/jquery/jquery-1.4.1.min.js") %>" type="text/javascript"></script>

<script src="<%= ResolveClientUrl("~/js/AutoComplete/jquery.autocomplete.js") %>" type="text/javascript"></script>
 
   
        <script type="text/javascript">
            $(function(){
             var data = '<%=searchChar%>'.split(";");
            $("#ctl00_ContentPlaceHolder1_ucTxtSearch_txtSearch").autocomplete(data);
            });
      </script>
    <link rel="stylesheet" href="~/css/AutoComplete/jquery.autocomplete.css"  type="text/css" />

 

"<%=searchChar%>" , is the variable sent from behind code, contains suggestion criteria data. It should be spilted by ";" char.

"#ctl00_ContentPlaceHolder1_ucTxtSearch_txtSearch", is clientID, it depends on your component ID.

 

Oke then, may it helps.

Unable to generate a temporary class (result=1). error CS2001: Source file ‘C:\WINDOWS\TEMP\xxxx.cs’ could not be found error CS2008: No inputs specified

Error as above happened while the web application running from remote computer

So, you must do a little things in the C:\Windows\Temp directory :

  1. Right click temp folder
  2. Open Security Tab
  3. Add ASPNET user in it, or NETWORK SERVICE user


 

Cheers

How to find Public Key Token

Here You must type on the command dos prompt :

" sn -T mysql.web.dll "


 

Cheers, hope could help

Cookie Iframe Problem on IE

Applications that use IFrame to call content from another web page, will be slightly impaired if the browser is Internet Explorer (IE). As for other browsers like Mozilla will be running normally. This happens because IE does not accept variables, in the form of session & cookies from unrecognize third party . IE only recognize the cookie / session that already meet the W3C standard called Platform for Privacy Preferences (P3P).

The Following tips :

1. The simplest way: Open IE, select the option Tools - Internet Options. On the Privacy tab, change the level setting to Low. Close IE and reopen, then your application will run normally. But this is inefficient way, because they have to change the IE settings on all clients.

2. This method is also simple, is adding one line of code on pages that do create session / cookies.


 

PHP:

header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');


 

ASP.NET:

HttpContext.Current.Response.AddHeader("p3p","CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");



The second is better, and no need to do the first.

Guaranteed your application will run properly.

Ok, may it helps

Thanks

"The web services enumeration components are not available"

For who met with the error "The web services enumeration components are not available. You need to reinstall Visual Studio to add web references to your application", when working with Web Service or Windows Communication Foundation, you can type the following

devenv / resetskippkgs

on Visual Studio 2005/2008 command prompt
Now you can continue your work without being haunted error message.

Ok, may it helps