12.7 ジオコーディング・サービス(XML API)の使用

SQL APIの他に、Oracle Spatialではジオコーディング・サービスのXML APIも提供され、これを使用して住所をジオコードできます。

Javaジオコーダ・アプリケーション・エンジンでは、Oracle Databaseに格納されたジオコーダ・データを問い合せることによって、住所の国際標準化、ジオコーディング、およびPOIの一致が行われます。未解析の住所のサポートにより、顧客アプリケーションに柔軟性と利便性が追加されます。

このジオコーディング・サービスは、WebLogic Server環境にデプロイできるJava 2 Enterprise Edition (J2EE) Webアプリケーションとして実装されます。

図12-1に、ジオコーディング・サービスを使用する基本的なアクション・フローを示します(クライアントは、リモートのジオコーディング・サービス・インスタンスを探してジオコーディング・リクエストを送信し、ジオコーディング・サービス・インスタンスから戻されたレスポンスを処理します)。

図12-1 Spatialジオコーディング・サービスを使用した基本的なアクション・フロー

図12-1の説明が続きます
図12-1「Spatialジオコーディング・サービスを使用した基本的なアクション・フロー」の説明

次に、図12-1について説明します。

  1. クライアントは、ジオコードする1つ以上の入力住所を含むXMLジオコーディング・リクエストを、HTTPプロトコルを使用してジオコーディング・サービスに送信します。

  2. ジオコーディング・サービスは、入力リクエストを解析して、入力住所をデータベース内で検索します。

  3. ジオコーディング・サービスは、ジオコードされた結果をXML形式で、HTTPプロトコルを使用してクライアントに送信します。

データベースにジオコーダ・スキーマをロードした後、それを使用する前にJ2EEジオコーダを構成する必要があります(「J2EEジオコーダのデプロイおよび構成」を参照)

12.7.1 J2EEジオコーダのデプロイおよび構成

J2EEジオコーダはジオコーディング・リクエストを処理し、レスポンスを生成します。このジオコーディング・サービスを有効にするには、Oracle WebLogic Serverを使用してgeocoder.ear.zipファイルをデプロイする必要があります。ジオコーディング・サービスをデプロイおよび構成するには、次のステップを実行します。

  1. Oracle WebLogic Serverを使用してジオコーダをデプロイします。
    1. $ORACLE_HOME/md/jlibディレクトリにあるgeocoder.ear.zipファイルを適切なディレクトリに解凍します。結果のディレクトリ構造は、$geocoder.ear/web.war/...となります。

    2. WebLogic Serverコンソール(たとえば、http://<hostname>:7001/console)にログオンし、「デプロイメント」からgeocoder.earファイルをインストールします。デプロイメントの名前geocoderを受け入れ、「場所」オプション「Make the deployment accessible from the following location」を選択します。

  2. URL http://<hostname>:<port>/geocoderを使用して、Webブラウザでジオコーダのようこそページを起動します。ようこそページで、「管理」リンクを選択し、管理者(weblogic)のユーザー名およびパスワードを入力します。

    ノート:

    デフォルトのWebLogic管理者のユーザー名(weblogic)を使用していない場合は、$geocoder.ear/web.war/WEB-INF/ディレクトリにあるweblogic.xmlファイルを編集する必要があります。<principal-name>weblogic</principal-name>をWebLogic Server管理者のユーザー名に置換します(<principal-name>my_weblogic_admin</principal-name>など)。

    ようこそページが表示されない場合は、新しくデプロイされたジオコーディング・サービスが正常に起動されたことを確認してください。(WebLogic Server 12.1以上を実行し、Oracle Database 12.2以上のgeocoder.ear.zipファイルを使用しているものとします。)

  3. ジオコーダ構成ファイル(geocodercfg.xml)を変更します。少なくとも1つの<geocoder>要素のコメントを解除し、その<geocoder>要素の<database>要素属性を、データベースの構成が反映されるように変更します。このファイルについては、「geocodercfg.xmlファイルの構成」を参照してください。
  4. ファイルに対する変更を保存し、ジオコーダを再起動します。
  5. URL http://<hostname>:<port>/geocoderのようこそページに移動し、XMLジオコーディング・リクエスト・ページを実行することによって、データベース接続を確認します。(このデモには、米国のジオコーダ・データが必要です。)

    例は、ジオコーディング・サービスの様々な機能を実例を使用して説明するために使用できます。「ジオコーディング・リクエストのXMLスキーマ定義および例」に示すXML APIについて学習するよい方法は、URL http://<hostname>:<port>/geocoder/gcxmlreq_exp_af.htmlの例を確認することです。

12.7.1.1 geocodercfg.xmlファイルの構成

geocodercfg.xmlファイルの<database>要素を編集して、ジオコーディング・データがロードされるデータベースとスキーマを指定する必要があります。geocodercfg.xmlファイルは、ジオコーダのようこそページにある管理者リンクを介してアクセスされ、ジオコーダ・アプリケーションの$geocoder.ear/web.war/WEB-INF/configディレクトリに格納されています

geocodercfg.xmlファイルの各<geocoder>要素は、ジオコーダ・スキーマが存在するデータベースのジオコーダを定義します。<database>要素は、ジオコーダのデータベース接続を定義します。Oracle Database 12.2では、データベース接続は、事前定義されたコンテナ・データ・ソースのJNDI名(container_ds)を指定して定義します。データ・ソースの定義の詳細は、WebLogic Serverのドキュメント、WebLogic JDBCの構成と管理のJDBCデータ・ソースの作成に関する項を参照してください。

例12-6に、<database>要素の定義を示します。この定義では、あらかじめ定義したコンテナ・データ・ソースのJNDI名を使用しています。

例12-6 <database>要素定義

<database container_ds="jdbc/gc_usa"
          load_db_parser_profiles="true" />

<database>要素の属性は次のとおりです。

  • container_dsは、事前定義のデータ・ソースのJNDI名を指定します。

  • load_db_parser_profilesは、指定されたデータベース接続から住所パーサー・プロファイルをロードするかどうかを指定します。ジオコーダ・データにパーサー・プロファイル表を指定する場合、このパラメータをtrueに設定することをお薦めします。値がtrueの場合、住所パーサー・プロファイルはジオコーダ・スキーマからロードされ、それ以外の場合は、パーサー・プロファイルは../applications/geocoder/web/WEB-INF/parser_profiles/<country-name>.ppr(たとえば、usa.ppr)にあるアプリケーションからロードされます。

12.7.2 ジオコーディング・リクエストのXMLスキーマ定義および例

ジオコーディング・リクエスト(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>

例12-7に、異なる住所形式および形式化されていない住所を使用した、3つの住所(2つの異なる実際の物理的な住所を示す)をジオコードするリクエストを示します。

例12-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>

12.7.3 ジオコーディング・レスポンスのXMLスキーマ定義および例

ジオコーディング・レスポンスには、経度/緯度の点、一致コード、複数の一致の可能性と一致なしの表示、エラー・メッセージなど、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:enumeration value="12"/>
        </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>

例12-8に、「ジオコーディング・リクエストのXMLスキーマ定義および例」例12-7のリクエストに対するレスポンスを示します。

例12-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>