SQL APIの他に、Oracle Spatial and Graphではジオコーディング・サービスのXML APIも提供され、これを使用して住所をジオコードすることができます。Javaジオコーダ・アプリケーション・エンジンでは、Oracle Databaseに格納されたジオコーダ・データを問い合せることによって、住所の国際標準化、ジオコーディング、およびPOIの一致が行われます。未解析の住所のサポートにより、顧客アプリケーションに柔軟性と利便性が追加されます。
このジオコーディング・サービスは、WebLogic Server環境でデプロイできるJava 2 Enterprise Edition (J2EE) Webアプリケーションとして実装されます。
図11-1に、ジオコーディング・サービスを使用する基本的なアクション・フローを示します(クライアントは、リモートのジオコーディング・サービス・インスタンスを探してジオコーディング・リクエストを送信し、ジオコーディング・サービス・インスタンスから戻されたレスポンスを処理します)。
次に、図11-1について説明します。
クライアントは、ジオコードする1つ以上の入力住所を含むXMLジオコーディング・リクエストを、HTTPプロトコルを使用してジオコーディング・サービスに送信します。
ジオコーディング・サービスは、入力リクエストを解析して、入力住所をデータベース内で検索します。
ジオコーディング・サービスは、ジオコードされた結果をXML形式で、HTTPプロトコルを使用してクライアントに送信します。
データベースにジオコーダ・スキーマをロードした後、それを使用する前にJ2EEジオコーダを構成する必要があります(「J2EEジオコーダのデプロイおよび構成」を参照)
J2EEジオコーダはジオコーディング・リクエストを処理し、レスポンスを生成します。このジオコーディング・サービスを有効化するには、Oracle WebLogic Serverを使用してgeocoder.ear.zipファイルをデプロイする必要があります。ジオコーディング・サービスをデプロイおよび構成するには、次の手順を実行します。
Spatial and Graphに付属するデフォルトのgeocodercfg.xmlファイルの<database>要素を編集して、ジオコーディング・データがロードされるデータベースとスキーマを指定する必要があります。
このファイルの各<geocoder>要素は、ジオコーダ・スキーマが存在するデータベースのジオコーダを定義します。<database>要素は、ジオコーダのデータベース接続を定義します。Oracle 11g以上では、データベース接続を定義する方法が2つあります(JDBCデータベース接続パラメータを提供する方法と、事前定義のコンテナ・データ・ソースのJNDI名(container_ds)を提供する方法です)。
例11-6に、<database>要素を定義する2つの異なる方法を示します。1つ目の定義ではJDBC接続を指定し、2つ目の定義では事前定義のコンテナ・データ・ソースのJNDI名を使用しています。
例11-6 <database>要素定義
<database name="gcdatabase"
host="gisserver.example.com"
port="1521"
sid="orcl"
mode="thin"
user="geocoder_us"
password="geocoder_us"
load_db_parser_profiles="true" />
<database container_ds="jdbc/gc_europe"
load_db_parser_profiles="true" />
<database>要素の属性は次のとおりです。
nameは、データベース接続の記述名です(データベースへの接続には使用されません)。
host、portおよびsidにより、データベースを識別します。
modeにより、接続のために使用するJDBCドライバの種類を識別します。
userおよびpasswordは、ジオコーディング・データが格納されているスキーマに対する、データベース・ユーザーのユーザー名とパスワードです。
load_db_parser_profilesは、指定されたデータベース接続から住所パーサー・プロファイルをロードするかどうかを指定します。trueの場合、住所パーサー・プロファイルはジオコーダ・スキーマからロードされ、それ以外の場合は、パーサー・プロファイルは../applications/geocoder/web/WEB-INF/parser_profiles/<country-name>.ppr (たとえば、usa.ppr)にあるアプリケーションからロードされます。Oracle 11gより前は、パーサー・プロファイルはアプリケーションからのみロードされていました。このパラメータはtrueに設定する必要があります。
container_dsは、事前定義のデータ・ソースのJNDI名を指定します。
ジオコーディング・リクエスト(HTTP GETまたはPOSTメソッド)の場合、そのリクエストには、xml_requestというパラメータがあり、その値は、リクエストのXML文書が含まれる文字列であると想定されます。入力XML文書には、ジオコードを行うために必要な入力住所が記述されます。1つのXMLリクエストには、1つ以上の入力住所を含めることができます。いくつかの国際化された住所形式は、入力住所の記述に使用できます。(また、入力XML APIでは、経度/緯度で通りの住所を指定する、逆ジオコードもサポートされています。)
ジオコーディング・リクエストのXMLスキーマ定義(XSD)は、次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<!-- Schema for an XML geocoding request that takes one or more input_locations and supports reverse geocoding using the input_location's attributes -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:complexType name="address_lineType">
<xsd:attribute name="value" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:complexType name="address_listType">
<xsd:sequence>
<xsd:element name="input_location" type="input_locationType"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="gdf_formType">
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="street" type="xsd:string"/>
<xsd:attribute name="intersecting_street" type="xsd:string"/>
<xsd:attribute name="builtup_area" type="xsd:string"/>
<xsd:attribute name="order8_area" type="xsd:string"/>
<xsd:attribute name="order2_area" type="xsd:string"/>
<xsd:attribute name="order1_area" type="xsd:string"/>
<xsd:attribute name="country" type="xsd:string"/>
<xsd:attribute name="postal_code" type="xsd:string"/>
<xsd:attribute name="postal_addon_code" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="gen_formType">
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="street" type="xsd:string"/>
<xsd:attribute name="intersecting_street" type="xsd:string"/>
<xsd:attribute name="sub_area" type="xsd:string"/>
<xsd:attribute name="city" type="xsd:string"/>
<xsd:attribute name="region" type="xsd:string"/>
<xsd:attribute name="country" type="xsd:string"/>
<xsd:attribute name="postal_code" type="xsd:string"/>
<xsd:attribute name="postal_addon_code" type="xsd:string"/>
</xsd:complexType>
<xsd:element name="geocode_request">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="address_list" type="address_listType"/>
</xsd:sequence>
<xsd:attribute name="vendor" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="input_addressType">
<xsd:choice>
<xsd:element name="us_form1" type="us_form1Type"/>
<xsd:element name="us_form2" type="us_form2Type"/>
<xsd:element name="gdf_form" type="gdf_formType"/>
<xsd:element name="gen_form" type="gen_formType"/>
<xsd:element name="unformatted" type="unformattedType"/>
</xsd:choice>
<xsd:attribute name="match_mode" default="relax_postal_code">
<xsd:simpleType>
<xsd:restriction base="xsd:NMTOKEN">
<xsd:enumeration value="exact"/>
<xsd:enumeration value="relax_street_type"/>
<xsd:enumeration value="relax_poi_name"/>
<xsd:enumeration value="relax_house_number"/>
<xsd:enumeration value="relax_base_name"/>
<xsd:enumeration value="relax_postal_code"/>
<xsd:enumeration value="relax_builtup_area"/>
<xsd:enumeration value="relax_all"/>
<xsd:enumeration value="DEFAULT"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
<xsd:complexType name="input_locationType">
<xsd:sequence>
<xsd:element name="input_address" type="input_addressType"
minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"/>
<xsd:attribute name="country" type="xsd:string"/>
<xsd:attribute name="longitude" type="xsd:string"/>
<xsd:attribute name="latitude" type="xsd:string"/>
<xsd:attribute name="x" type="xsd:string"/>
<xsd:attribute name="y" type="xsd:string"/>
<xsd:attribute name="srid" type="xsd:string"/>
<xsd:attribute name="multimatch_number" type="xsd:string" default="1000"/>
</xsd:complexType>
<xsd:complexType name="unformattedType">
<xsd:sequence>
<xsd:element name="address_line" type="address_lineType"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="country" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="us_form1Type">
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="street" type="xsd:string"/>
<xsd:attribute name="intersecting_street" type="xsd:string"/>
<xsd:attribute name="lastline" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="us_form2Type">
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="street" type="xsd:string"/>
<xsd:attribute name="intersecting_street" type="xsd:string"/>
<xsd:attribute name="city" type="xsd:string"/>
<xsd:attribute name="state" type="xsd:string"/>
<xsd:attribute name="zip_code" type="xsd:string"/>
</xsd:complexType>
</xsd:schema>
例11-7に、異なる住所形式および形式化されていない住所を使用した、3つの住所(2つの異なる実際の物理的な住所を示す)をジオコードするリクエストを示します。
例11-7 ジオコーディング・リクエスト(XML API)
<?xml version="1.0" encoding="UTF-8"?>
<geocode_request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../geocode_request.xsd">
<address_list>
<input_location id="1">
<input_address>
<us_form2 name="Oracle" street="500 Oracle Parkway" city="Redwood City"
state="CA" zip_code="94021"/>
</input_address>
</input_location>
<input_location id="2">
<input_address>
<gdf_form street="1 Oracle Drive" builtup_area="Nashua" order1_area="NH"
postal_code="03062" country="US"/>
</input_address>
</input_location>
<input_location id="3">
<input_address>
<gen_form street="1 Oracle Drive" city="Nashua" region="NH" postal_code="03062" country="US"/>
</input_address>
</input_location>
<input_location id="4">
<input_address>
<unformatted country="UNITED STATES">
<address_line value="Oracle NEDC"/>
<address_line value="1 Oracle drive "/>
<address_line value="Nashua "/>
<address_line value="NH"/>
</unformatted>
</input_address>
</input_location>
</address_list>
</geocode_request>
ジオコーディング・レスポンスには、経度/緯度の点、一致コード、複数の一致の可能性と一致なしの表示、エラー・メッセージなど、1つ以上の標準化された住所が含まれます。
ジオコーディング・レスポンスのXMLスキーマ定義(XSD)は、次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<!-- Schema for an XML geocoding response -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:complexType name="geocodeType">
<xsd:sequence>
<xsd:element name="match" type="matchType" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string" use="required"/>
<xsd:attribute name="match_count" type="xsd:string"/>
</xsd:complexType>
<xsd:element name="geocode_response">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="geocode" type="geocodeType" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="matchType">
<xsd:sequence>
<xsd:element name="output_address" type="output_addressType"/>
</xsd:sequence>
<xsd:attribute name="sequence" type="xsd:string" use="required"/>
<xsd:attribute name="longitude" type="xsd:string" use="required"/>
<xsd:attribute name="latitude" type="xsd:string" use="required"/>
<xsd:attribute name="match_code" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:NMTOKEN">
<xsd:enumeration value="0"/>
<xsd:enumeration value="1"/>
<xsd:enumeration value="2"/>
<xsd:enumeration value="3"/>
<xsd:enumeration value="4"/>
<xsd:enumeration value="10"/>
<xsd:enumeration value="11"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="error_message" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="output_addressType">
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="house_number" type="xsd:string"/>
<xsd:attribute name="street" type="xsd:string"/>
<xsd:attribute name="builtup_area" type="xsd:string"/>
<xsd:attribute name="order1_area" type="xsd:string"/>
<xsd:attribute name="order8_area" type="xsd:string"/>
<xsd:attribute name="country" type="xsd:string"/>
<xsd:attribute name="postal_code" type="xsd:string"/>
<xsd:attribute name="postal_addon_code" type="xsd:string"/>
<xsd:attribute name="side" type="xsd:string"/>
<xsd:attribute name="percent" type="xsd:string"/>
<xsd:attribute name="edge_id" type="xsd:string"/>
</xsd:complexType>
</xsd:schema>
例11-8に、「ジオコーディング・リクエストのXMLスキーマ定義および例」の例11-7のリクエストに対するレスポンスを示します。
例11-8 ジオコーディング・レスポンス(XML API)
<?xml version="1.0" encoding="UTF-8"?>
<geocode_response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../geocode_response.xsd">
<geocode id="1" match_count="1">
<match sequence="0"
longitude="-122.26193971893862" latitude="37.53195483966782"
match_code="10" error_message="????#ENUT?B281C??">
<output_address name="" house_number="500" street="ORACLE PKY"
builtup_area="REDWOOD CITY" order1_area="CA" order8_area=""
country="US" postal_code="94065" postal_addon_code="" side="L"
percent="0.33166666666666667" edge_id="28503563"/>
</match>
</geocode>
<geocode id="2" match_count="1">
<match sequence="0"
longitude="-71.45937299307225" latitude="42.70784494226865"
match_code="1" error_message="????#ENUT?B281CP?">
<output_address name="" house_number="1" street="ORACLE DR"
builtup_area="NASHUA" order1_area="NH" order8_area=""
country="US" postal_code="03062" postal_addon_code="" side="L"
percent="0.01" edge_id="22325991"/>
</match>
</geocode>
<geocode id="3" match_count="1">
<match sequence="0"
longitude="-71.45937299307225" latitude="42.70784494226865"
match_code="1" error_message="????#ENUT?B281CP?">
<output_address name="" house_number="1" street="ORACLE DR"
builtup_area="NASHUA" order1_area="NH" order8_area=""
country="US" postal_code="03062" postal_addon_code="" side="L"
percent="0.01" edge_id="22325991"/>
</match>
</geocode>
<geocode id="4" match_count="1">
<match sequence="0"
longitude="-71.45937299307225" latitude="42.70784494226865"
match_code="1" error_message="????#ENUT?B281CP?">
<output_address name="" house_number="1" street="ORACLE DR"
builtup_area="NASHUA" order1_area="NH" order8_area=""
country="US" postal_code="03062" postal_addon_code="" side="L"
percent="0.01" edge_id="22325991"/>
</match>
</geocode>
</geocode_response>