Lishan
 Level 4 Posts:99

 |
|
|
Hi Scott, Any news? Is the info I provided is still no sufficient? Thanks! Lishan |
|
|
|
|
Scott
 MVP Posts:179

 |
|
|
Lishan,
Sorry for replying you so late, I re-created your problem used the sample code and dbf file what you attached, I found out there are two problems in your code so it caused the exception, I list the error code below:
1, In the FindAddress web method:
geocoder.MatchingPlugIns.Add(new CustomStreetDbfMatchingPlugin(dbfPath + "VANCOUVER-index.dbf"));
2, In the CustomStreetDbfMatchingPlugin class, please see your constructors:
public CustomStreetDbfMatchingPlugin() : this(string.Empty) { } public CustomStreetDbfMatchingPlugin(string pathFileName) { this.PathFileName = pathFileName; } public CustomStreetDbfMatchingPlugin(string pathFileName, DbfMatchingPluginReadWriteMode mode) { this.ReadWriteMode = mode; this.PathFileName = pathFileName; }
They are incorrect, you need to write your own constructors according to the following code:
public CustomStreetDbfMatchingPlugin() :
this(string.Empty)
{
}
public CustomStreetDbfMatchingPlugin(string pathFileName):base(pathFileName)
{
this.PathFileName = pathFileName;
}
public CustomStreetDbfMatchingPlugin(string pathFileName, DbfMatchingPluginReadWriteMode mode): base(pathFileName, mode)
{
this.ReadWriteMode = mode;
this.PathFileName = pathFileName;
}
You can see that each constructor should pass the necessary parameters to the base class,
After I modified your code according to my changes above, your problem can be resolved correctly, please have a try,
Thanks,
Scott, |
|
|
|
|
Lishan
 Level 4 Posts:99

 |
|
|
Hi Scott,
Thanks! That problem is solved with your help.
1. now i am trying to override MatchCore. If I want to get the records from the dbf file, I can't just use GetRecord(record index) eh? I tried. it just failed. so I think I need to open/connect the dbf file and read the records from the file? it'd probably straightforward but I just couldn't get it right.. =\
here's my code for the connecting to the dbf file and reading from it:
OdbcConnection oConn = new OdbcConnection();<br />
oConn.ConnectionString ="Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=folderpath;Exclusive=No; Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";<br />
OdbcCommand oCmd = oConn.CreateCommand(); oCmd.CommandText = "SELECT * FROM str";<br />
//oCmd.CommandText = "SELECT * FROM str.dbf";<br />
oConn.Open();<br />
OdbcDataReader dr = oCmd.ExecuteReader();<br />
It fails at the last line and throws error: "Microsoft JScript runtime error: Sys.Net.WebServiceFailedException: The server method 'findAddress' failed with the following error: System.Data.Odbc.OdbcException-- ERROR [42S02] [Microsoft][ODBC dBase Driver] The Microsoft Jet database engine could not find the object 'str'. Make sure the object exists and that you spell its name and the path name correctly "
I have attached the dbf file.
2. in what circumstance or meeting what criteria can GetRecord(int) be used properly?
Thanks!
Lishan |
str.zip
|
|
|
|
Scott
 MVP Posts:179

 |
|
|
Lishan, I think maybe your method is not so properly to get the record for the index dbf file, there is an easy way to get it, if you override your own matching plugin inherited from the DbfMatchingPlugin, there is a property that names RecordCount, it can get the record count of the DBF file directly, you don’t need to use the ODBC object to open the DBF file. If you have any questions please let me know, Thanks, Scott, |
|
|
|
|
Lishan
 Level 4 Posts:99

 |
|
|
Hi Scott,
yea. the RecordCount returns the number of records in the dbf. but I have problem getting the record itself and extact data from it. ..
Lishan |
|
|
|
|
Scott
 MVP Posts:179

 |
|
|
Lishan, Can you supply your sample so that I can reproduce the problem on getting the record count for the attached shape file, I can get the record count for this shape file correctly, I'm not sure where is the exact problem, so if you can supply a sample to reproduce the problem, it is useful for resolving this problem, Thanks, Scott, |
|
|
|
|
Lishan
 Level 4 Posts:99

 |
|
|
Hi Scott,
I have attached the dbf file and the code for MatchCore method. I don't just need record count. I need the access the fields of the records.
and.... Can the matchingPlugin directly deal with shape files w/o converting them to dbf or other file formats?? (sounds like it in your prev reply??.. )
Thanks very much for your help.
Lishan
|
partialAddress.zip
|
|
|
|
Scott
 MVP Posts:179

 |
|
|
Lishan, I understand what you want to do, you want to access the fields for each record of the index dbf file, currently, we don't public the DbaseEngine classes in the MapSuiteGeocoder or MapSuiteCore, so you don't access the fields of the records used the MapSuiteGeocoder or MapSuiteCore. I think you only can access them through the Odbc or OleDb object, I just provide you the OleDb object to access the dbf file below:
string path = System.IO.Path.GetDirectoryName(@"C:\Documents and Settings\Administrator\Desktop\partialAddress\partialAddress\str\str.dbf");
string FileName = System.IO.Path.GetFileName(@"C:\Documents and Settings\Administrator\Desktop\partialAddress\partialAddress\str\str.dbf");
string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path;
System.Data.OleDb.OleDbConnection dbfconn = new System.Data.OleDb.OleDbConnection();
dbfconn.ConnectionString = conn;
string cmd = "select * from " + FileName;
System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter(cmd, dbfconn);
DataSet dsResult = new DataSet();
adapter.Fill(dsResult, "str");
DataTable table = dsResult.Tables[0];
dsResult.Dispose();
adapter.Dispose();
dbfconn.Close();
dbfconn.Dispose();
Thanks, Scott, |
|
|
|
|
Tracy
 Level 3 Posts:83

 |
|
|
Hi,
I created a dbf file that contains the following columns:
strColumns.Add(new DbfMatchingPluginColumn("ID_STIDX", DbfMatchingPluginColumnType.Long, 4));
strColumns.Add(new DbfMatchingPluginColumn("DT_STNAME", DbfMatchingPluginColumnType.String, 80));
strColumns.Add(new DbfMatchingPluginColumn("DT_LADDR", DbfMatchingPluginColumnType.String, 10));
strColumns.Add(new DbfMatchingPluginColumn("DT_LNADDR", DbfMatchingPluginColumnType.String, 10));
strColumns.Add(new DbfMatchingPluginColumn("DT_LADDRP", DbfMatchingPluginColumnType.String, 1));
strColumns.Add(new DbfMatchingPluginColumn("DT_RADDR", DbfMatchingPluginColumnType.String, 10));
strColumns.Add(new DbfMatchingPluginColumn("DT_RNADDR", DbfMatchingPluginColumnType.String, 10));
strColumns.Add(new DbfMatchingPluginColumn("DT_RADDRP", DbfMatchingPluginColumnType.String, 1));
strColumns.Add(new DbfMatchingPluginColumn("BB_CX", ThinkGeo.MapSuite.MapSuiteGeocoder.DbfMatchingPluginColumnType.Long, 4));
strColumns.Add(new DbfMatchingPluginColumn("BB_CY", ThinkGeo.MapSuite.MapSuiteGeocoder.DbfMatchingPluginColumnType.Long, 4));
strColumns.Add(new DbfMatchingPluginColumn("BB_ULX", ThinkGeo.MapSuite.MapSuiteGeocoder.DbfMatchingPluginColumnType.Long, 4));
strColumns.Add(new DbfMatchingPluginColumn("BB_ULY", ThinkGeo.MapSuite.MapSuiteGeocoder.DbfMatchingPluginColumnType.Long, 4));
strColumns.Add(new DbfMatchingPluginColumn("BB_LRX", ThinkGeo.MapSuite.MapSuiteGeocoder.DbfMatchingPluginColumnType.Long, 4));
strColumns.Add(new DbfMatchingPluginColumn("BB_LRY", ThinkGeo.MapSuite.MapSuiteGeocoder.DbfMatchingPluginColumnType.Long, 4));
I can view all the columns in this dbf file without any problems.
But then when I did the following, it raises an exception at the line where I want to get the value of DT_STNAME
Geocoder geocoderGeoStreets = new Geocoder(@"C:\Source\MapDataProcessing\bin\Debug\GeoCoder");
geocoderGeoStreets.MatchingPlugIns.Add(new DbfMatchingPlugin(@"C:\Source\MapDataProcessing\bin\Debug\GeoCoder\GeoStreets.dbf"));
geocoderGeoStreets.Open();
Collection<GeocoderMatch> matchResultStreets = geocoderGeoStreets.Match("0");
string street_idx = matchResultStreets[0].NameValuePairs["DT_STIDX"];
matchResultStreets doesn't seem to contain any of the DT columns from the file.
Thanks. |
|
|
|
|
Scott
 MVP Posts:179

 |
|
|
Tracy,
I have a few questions to ask you about your application below:
1, Did you override the MatchCore function that inherates to the DbfMatchingPlugin or MatchingPlugin?
2, Can you give me your sample code and shape file so that I can reproduce your problem exactly? Currently I'm not sure where is the proiblem from?
But I still have a suggestion for you, when you create your own plugin inherates the DbfMatchingPlugin or MatchingPlugin and you have your own index dbf file, you have to override the MatchCore function according to the own index dbf file structure.
Thanks,
Scott, |
|
|
|
|