AnsweredAssumed Answered

Error 999999 occurred when generating tile map package with arcpy, arcmap?

Question asked by tommybee on Sep 11, 2017

I am working with arcpy and arcmap tool generating a tile map package with .tpk suffix nowadays.

I have three map services at this time writing,

server tile map service,
server map service
local tile map service(.tpk)


This is my projection information of the area from arcmap information.

 

Projection information of my area
Tokyo_Transverse_Mercator
Authority: Custom

Projection: Transverse_Mercator
False_Easting: 200000.0
False_Northing: 500000.0
Central_Meridian: 127.0028902777778
Scale_Factor: 1.0
Latitude_Of_Origin: 38.0
Linear Unit: Meter (1.0)

Geographic Coordinate System: GCS_Tokyo
Angular Unit: Degree (0.0174532925199433)
Prime Meridian: Greenwich (0.0)
Datum: D_Tokyo
Spheroid: Bessel_1841
Semimajor Axis: 6377397.155
Semiminor Axis: 6356078.962818189
Inverse Flattening: 299.1528128

 

***Case 1. using arcpy***

 

The python code for generating tpk file is below,

 

arypy function - make a tpk file
def fireTileMapGen(self, iteminfo):
    tpkName = iteminfo[0]
    mxdPath = os.path.abspath(iteminfo[1])
    tpkPath = os.path.abspath(iteminfo[2])
    schemePath = os.path.abspath(iteminfo[3])
    lod = iteminfo[4]

    title = "Mobile Map"
    filetype = "PNG8"

    env.overwriteOutput = True

    try:
        self.tile_gen_status = arcpy.CreateMapTilePackage_management(
                          mxdPath,
                        "EXISTING",
                        tpkPath,
                        filetype,
                        lod,
                        schemePath,
                        title,
                        title)
    except Exception as myerr:
        arcpy.AddMessage(myerr)
        arcpy.AddMessage("There's a problem with the output.")
        return False

    return True

 

But, i always got an error message, 

 

ERROR 999999: Error executing function. Failed to execute (CreateMapTilePackage).

 

So, i tried another method ,which makes problem clear following by the url of esri.

 

http://support.esri.com/en/technical-article/000012213

 

It was also interrupted at the middle of processing.


***Case 2. Using different coordination system***

 

The parameters of projection in **Korea_2000_Korea_Central_Belt_2010**

is the same of the error one, so i used this parameter in the sheme file when generating tpk successfully following url.

 

https://developers.arcgis.com/net/latest/ios/guide/projected-coordinate-systems-part-2.htm

 

but i was not able to make it when displaying server tile and local cache together in my application with internal error message as follows,

 

java.lang.RuntimeException: Tiled layer has different spatial reference from the map.

 

ERROR 999999 wasn't contained enough information to me, so i made my own source code using java to find out what is more information through the logic that is why the above message is that of java's error 


So here is full source code except accessory class - layermananger that just store actual url and properties.
And more i've just modified the sample source code from that of esri.

 

Modified Tile information checking source 
/* Copyright 2014 Esri

All rights reserved under the copyright laws of the United States
and applicable international laws, treaties, and conventions.

You may freely redistribute and use this sample code, with or
without modification, provided you include the original copyright
notice and use restrictions.

See the use restrictions.*/
package com.tobee.esri.client.map;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;

import com.esri.client.local.ArcGISLocalTiledLayer;
import com.esri.core.geometry.Geometry;
import com.esri.core.geometry.Geometry.Type;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.map.Graphic;
import com.esri.core.symbol.SimpleFillSymbol;
import com.esri.core.symbol.SimpleLineSymbol;
import com.esri.core.symbol.SimpleMarkerSymbol;
import com.esri.core.tasks.ags.find.FindParameters;
import com.esri.core.tasks.ags.find.FindResult;
import com.esri.core.tasks.ags.find.FindTask;
import com.esri.map.ArcGISDynamicMapServiceLayer;
import com.esri.map.ArcGISTiledMapServiceLayer;
import com.esri.map.GraphicsLayer;
import com.esri.map.JMap;
import com.esri.map.LayerInitializeCompleteEvent;
import com.esri.map.LayerInitializeCompleteListener;

/***
* This sample demonstrates executing a FindTask, adding the results to a table,
* and zooming to a selected result.
*/
public class TSMSGisMapSearch {
// resources
final String SEVER_CACHE_SERVICE;
final String LOCAL_CACHE_SERVICE;
final String MAP_SERVICE;

// UI related
JTextField findText = new JTextField("Search word");
DefaultTableModel tblModelStateInfo;

// JMap
private JMap map;

// our graphics layer for highlighted geometries
private GraphicsLayer graphicsLayer;

// for zooming to a buffered geometry
// private static final double BUFFER_DISTANCE = 500000; // 500 km
private static final double BUFFER_DISTANCE = 50; // 50 m

// results of the Find task execution
private List<FindResult> findResults = null;
private JFrame appWindow;
private JDialog appDialog;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
public TSMSGisMapSearch(final String title, final TSMSLayerManager layerManager) {

//TSMSLayerManager.activateEsriService();
SEVER_CACHE_SERVICE = layerManager.getSERVER_CACHE_SERVIC_URL();
MAP_SERVICE = layerManager.getMAIN_MAP_SERVIC_URL();
LOCAL_CACHE_SERVICE = layerManager.getLOCAL_MAP_TILE_URL();

SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
// create the UI, including the map, for the application.
appWindow = createWindow(title);
appWindow.add(createUI());
appWindow.setVisible(true);
//appWindow.addWindowListener(new securityClosing());
} catch (Exception e) {
// on any error, display the stack trace.
e.printStackTrace();
}
}
});
}

public TSMSGisMapSearch(final JDialog owner, final String title, final TSMSLayerManager layerManager)
{

//TSMSLayerManager.activateEsriService();
SEVER_CACHE_SERVICE = layerManager.getSERVER_CACHE_SERVIC_URL();
MAP_SERVICE = layerManager.getMAIN_MAP_SERVIC_URL();
LOCAL_CACHE_SERVICE = layerManager.getLOCAL_MAP_TILE_URL();

SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
// create the UI, including the map, for the application.
appDialog = createDialog(owner, title);
appDialog.add(createUI());
appDialog.setVisible(true);
appDialog.addWindowListener(new securityClosing());
} catch (Exception e) {
// on any error, display the stack trace.
e.printStackTrace();
}
}
});
}

private class securityClosing extends WindowAdapter {
public void windowClosing(WindowEvent e) {
int option = JOptionPane.showOptionDialog(appWindow, "Are you sure you want to leave the program?",
"close map", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null);

if (option == JOptionPane.YES_OPTION) {
// try {
// if(Controller.dbInterface != null)
// Controller.dbInterface.removeObserver(Controller.rmiClient);
// } catch (RemoteException e1) {
// e1.printStackTrace();
// }
// System.exit(0);
map.dispose();

if(appDialog != null)
{
appDialog.setVisible(false);
appDialog.dispose();
}
else
{
appWindow.setVisible(false);
appWindow.dispose();
}

} else {
// Abbruch
if(appDialog != null)
{
appDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
}
else
{
appWindow.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
}

}
}
}

// ------------------------------------------------------------------------
// Core functionality
// ------------------------------------------------------------------------
/**
* This method creates and executes the FindTask to find the input text
*
*/
private void onFind() {
tblModelStateInfo.setRowCount(0);

// return if input text is not valid
if (findText.getText() == null || findText.getText().isEmpty()) {
return;
}

// -----------------------------------------------------------------------------------------
// Find task to find the search string specified by the user in all
// attributes of dynamic
// service
// -----------------------------------------------------------------------------------------
// create a Find task.
FindParameters params = new FindParameters();
params.setSearchText(findText.getText());
params.setLayerIds(new int[] { 20, 21, 22, 88, 98, 152 });
params.setOutputSpatialRef(map.getSpatialReference());

// execute the find task
FindTask task = new FindTask(MAP_SERVICE);
try {
findResults = task.execute(params);

if (findResults == null) {
return;
}

for (FindResult result : findResults) {
tblModelStateInfo.addRow(new Object[] { result.getAttributes().get(result.getDisplayFieldName()),
Integer.valueOf(result.getLayerId()), result.getLayerName(), result.getFoundFieldName(),
result.getValue() });
}
} catch (Exception e) {
e.printStackTrace();
}
}

// ------------------------------------------------------------------------
// Public methods
// ------------------------------------------------------------------------

/**
* Creates and displays the UI, including the map, for this application.
*/
public JComponent createUI() throws Exception {

// content pane
JComponent contentPane = new JPanel();
contentPane.setLayout(new BorderLayout(1, 0));

// map
map = createMap();

// input text and find button
JLabel findLabel = new JLabel(" ");
findLabel.setForeground(Color.WHITE);
findLabel.setFont(new Font(findLabel.getFont().getName(), findLabel.getFont().getStyle(), 14));
findText.setFont(new Font(findLabel.getFont().getName(), findLabel.getFont().getStyle(), 14));
findText.setMinimumSize(new Dimension(150, 25));
findText.setMaximumSize(new Dimension(150, 25));
findText.setColumns(10);
JLabel remainderLabel = new JLabel(" 속성을 TSMS Map에서 찾습니다.");
remainderLabel.setForeground(Color.WHITE);
remainderLabel.setFont(new Font(findLabel.getFont().getName(), findLabel.getFont().getStyle(), 14));
JButton findButton = new JButton("Find");
findButton.setFont(new Font(findLabel.getFont().getName(), findLabel.getFont().getStyle(), 14));
findButton.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
onFind();
}
});

// scrollable-table to display the FindResult information
tblModelStateInfo = new DefaultTableModel() {
private static final long serialVersionUID = 1L;

@Override
public boolean isCellEditable(int rowIndex, int mColIndex) {
return false;
}
};
// add the column headers
tblModelStateInfo.addColumn("Display Field");
tblModelStateInfo.addColumn("Layer Id");
tblModelStateInfo.addColumn("Layer Name");
tblModelStateInfo.addColumn("Found Field");
tblModelStateInfo.addColumn("Found Field Value");

final JTable stateInfoTable = new JTable(tblModelStateInfo);
JScrollPane tblStateInfoScrollable = new JScrollPane(stateInfoTable);
stateInfoTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
int rowId = stateInfoTable.getSelectedRow();
if (0 <= rowId && rowId < findResults.size()) {
highlightGeometry(findResults.get(rowId).getGeometryType(), findResults.get(rowId).getGeometry());
}
}
});

// panels to contain input text and find button
JPanel topPanel = new JPanel();
topPanel.setBackground(Color.BLACK);
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
topPanel.add(Box.createHorizontalGlue());
topPanel.add(findLabel);
topPanel.add(findText);
topPanel.add(remainderLabel);
topPanel.add(findButton);
topPanel.add(Box.createHorizontalGlue());

// panel to contain find results
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new BorderLayout());
bottomPanel.add(tblStateInfoScrollable, BorderLayout.CENTER);
bottomPanel.setPreferredSize(new Dimension(600, 150));

contentPane.add(topPanel, BorderLayout.NORTH);
contentPane.add(map, BorderLayout.CENTER);
contentPane.add(bottomPanel, BorderLayout.SOUTH);

return contentPane;
}

// ------------------------------------------------------------------------
// Private methods
// ------------------------------------------------------------------------
/**
* Creates a window.
*
* @return a window.
*/
private JFrame createWindow(final String title) {
JFrame window = new JFrame(title);
window.setBounds(100, 100, 1000, 700);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().setLayout(new BorderLayout(0, 0));

window.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent windowEvent) {
super.windowClosing(windowEvent);
map.dispose();
}
});

return window;
}

private JDialog createDialog(final JDialog owner, final String title) {
JDialog dialog = new JDialog(owner, title);
dialog.setBounds(100, 100, 1000, 700);
//window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
dialog.getContentPane().setLayout(new BorderLayout(0, 0));
/*
window.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent windowEvent) {
super.windowClosing(windowEvent);
map.dispose();
}
});
*/
return dialog;
}

/**
* Creates a map.
*
* @return a map.
*/
private JMap createMap() throws Exception {
final JMap jMap = new JMap();

// -----------------------------------------------------------------------------------------
// Base Layer - with US topology, focus on U.S by default
// -----------------------------------------------------------------------------------------
final ArcGISTiledMapServiceLayer serverCacheLayer = new ArcGISTiledMapServiceLayer(SEVER_CACHE_SERVICE);
// jMap.setExtent(new Envelope(-15000000, 2000000, -7000000, 8000000));
//jMap.setExtent(TSMSLayerManager.CURRENT_EXTENT);
serverCacheLayer.setMinScale(50000);
serverCacheLayer.setMaxScale(1000);


serverCacheLayer.addLayerInitializeCompleteListener(new LayerInitializeCompleteListener(){

@Override
public void layerInitializeComplete(LayerInitializeCompleteEvent arg0) {
SpatialReference sp = arg0.getLayer().getSpatialReference();

System.out.println("url >> " + arg0.getLayer().getUrl());


System.out.println(sp == null);
if(sp != null)
{
System.out.println(sp.getText());
}

}});

// -----------------------------------------------------------------------------------------
// Dynamic Layer - US Cities and States that we will search
// -----------------------------------------------------------------------------------------
final ArcGISDynamicMapServiceLayer dynamicLayer = new ArcGISDynamicMapServiceLayer(MAP_SERVICE);
dynamicLayer.setMinScale(500);
dynamicLayer.setOpacity(0.6f);

dynamicLayer.addLayerInitializeCompleteListener(new LayerInitializeCompleteListener(){

@Override
public void layerInitializeComplete(LayerInitializeCompleteEvent arg0) {
SpatialReference sp = arg0.getLayer().getSpatialReference();

System.out.println("url >> " + arg0.getLayer().getUrl());


System.out.println(sp == null);
if(sp != null)
{
System.out.println(sp.getText());
}

}});

final ArcGISLocalTiledLayer localTileLayer = new ArcGISLocalTiledLayer(LOCAL_CACHE_SERVICE);
localTileLayer.setMinScale(50000);
localTileLayer.setMaxScale(1000);

localTileLayer.addLayerInitializeCompleteListener(new LayerInitializeCompleteListener(){

@Override
public void layerInitializeComplete(LayerInitializeCompleteEvent arg0) {
SpatialReference sp = arg0.getLayer().getSpatialReference();
System.out.println(sp == null);
if(sp != null)
{
//System.out.println(sp.getID());

System.out.println(sp.getText());
}

}});

jMap.getLayers().add(localTileLayer);
jMap.getLayers().add(serverCacheLayer);
//jMap.getLayers().add(dynamicLayer);

// -----------------------------------------------------------------------------------------
// Graphics Layer - to highlight a selected feature
// -----------------------------------------------------------------------------------------
graphicsLayer = new GraphicsLayer();
jMap.getLayers().add(graphicsLayer);

return jMap;
}

/**
* Display a geometry on the map for the selected table row
*
* @param geometryType
* @param geometry
*/
private void highlightGeometry(Type geometryType, Geometry geometry) {
if (geometryType == null || geometry == null) {
return;
}

// -----------------------------------------------------------------------------------------
// Add a graphic for the selected feature to the graphics layer
// -----------------------------------------------------------------------------------------
graphicsLayer.removeAll();
switch (geometryType) {
case POINT:
graphicsLayer.addGraphic(
new Graphic(geometry, new SimpleMarkerSymbol(Color.BLUE, 8, SimpleMarkerSymbol.Style.DIAMOND)));
break;
case POLYLINE:
graphicsLayer.addGraphic(
new Graphic(geometry, new SimpleLineSymbol(Color.BLUE, 4, SimpleLineSymbol.Style.SOLID)));
break;
case POLYGON:
graphicsLayer.addGraphic(new Graphic(geometry, new SimpleFillSymbol(Color.BLUE)));
break;
default:
break;
}

graphicsLayer.setOpacity(0.5f);

// -----------------------------------------------------------------------------------------
// Zoom to the highlighted graphic
// -----------------------------------------------------------------------------------------
Geometry geometryForZoom = GeometryEngine.buffer(geometry, map.getSpatialReference(), BUFFER_DISTANCE,
map.getSpatialReference().getUnit());
map.zoomTo(geometryForZoom);
}

}

 

I already have old version of tpk file with the Tokyo projection(bessel 1841 to be exact).

but I can not generate the right tpk file recently with the arcpy function i presented.

 

The source is quite long but the main consideration part is here

 

jMap.getLayers().add(localTileLayer); //tpk
jMap.getLayers().add(serverCacheLayer); // server cache
jMap.getLayers().add(dynamicLayer); // server's map service

 

to see if two tpks with different coordination systems which are tokyo datum and korea datum, give me some clue to trace what was wrong.

 

I've finally found the error messages i mentioned before.

 

java.lang.RuntimeException: Tiled layer has different spatial reference from the map.


This is error projection parameters in the scheme file but must be generated while generating tpk is, 

 

 

Projection in the scheme in xml file
PROJCS["Tokyo_Transverse_Mercator",GEOGCS["GCS_Tokyo",DATUM["D_Tokyo",
SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Greenwich",0.0],
UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],
PARAMETER["False_Easting",200000.0],
PARAMETER["False_Northing",500000.0],
PARAMETER["Central_Meridian",127.0028902777778],
PARAMETER["Scale_Factor",1.0],PARAMETER["Latitude_Of_Origin",38.0],
UNIT["Meter",1.0]]

 

 

Next, this is the projection that i've got a tpk file but diplay-mismatch.

 

Header 1
PROJCS["Korean_1985_Modified_Korea_Central_Belt",GEOGCS["GCS_Korean_Datum_1985",DATUM["D_Korean_Datum_1985",
SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Greenwich",0.0],
UNIT["Degree",0.0174532925199433]],
PROJECTION["Transverse_Mercator"],
PARAMETER["False_Easting",200000.0],
PARAMETER["False_Northing",500000.0],
PARAMETER["Central_Meridian",127.0028902777778],
PARAMETER["Scale_Factor",1.0],
PARAMETER["Latitude_Of_Origin",38.0],UNIT["Meter",1.0]]

 

I am still digging to solve the problem, but I don't know the missing point.

So I need some useful information to trace my problem more deeper.

 

Any suggestion and help will be appreciated.

Outcomes