Saturday, December 30, 2006

Convert Between Polygon Shape File and Arc/Info Coverage

Sometimes you want to take advantage of the old Arc/Info command lines... e.g., you want to run CLEAN, or you have many files to process and you want to run a simple script.

However, when converting between a shape file and arc/info coverage, you usually lose attribute data. To preserve attribute data, follow this example:

# import as region
shapearc oxbld.shp oxr REGION

# clean poly
clean oxr oxrc # # POLY

# export region
arcshape oxrc REGIONS.REGION oxr

Friday, December 01, 2006

javascript in href

There are two ways to use javascript in a href tag, e. g.,

1. <a href="javascript:doSomething()">...</a>
2. <a href="#" onclick="doSomething(); return false">...</a>


When using Microsoft HTA, however, only the second approach works. The first one will pop up a new window when the link is clicked, even under IE7.

Tuesday, April 25, 2006

Request Encoding

In JSP you have to manually set request encoding otherwise it will default to iso-8859-1. With the default you won't access any param whose value is not in iso-8859-1 encoding correctly. e.g., the copyright character "©".

To set request encoding, use jstl:

xmlns:fmt=http://java.sun.com/jsp/jstl/fmt

<fmt:requestencoding value="utf-8">

Paste High DPI Image from Clipboard into Photoshop

You want to convert a MS Word graph into image, using Photoshop.

Copy to clipboard in Word.
New file in Photoshop.

When you New file from clipboard, the initial settings is 72DPI. Change the units to inch, dpi to 300. New. Paste. Result is incorrect.

Do not close the window. New file again. This time the pixel settings are much larger. Change the DPI to 300, and units to inch. The dimensions should match Word. Now paste.

cvs server on cygwin

If you want to connect from eclipse to a cvs running on cygwin, cygwin version 1.5.19 won't suffix. It has a bug that returns an unexpected errorno when cvs attempts to create "/tmp/cvs-serv???/.". The latest cygwin snapshort solved it.

With that bug corrected, in eclipse select extssh method.

Friday, December 02, 2005

JavaScript XmlHttp

A simple cross-platform XmlHttp code snippet:

function newXmlHttp() {
    if (window.XMLHttpRequest) { 
        return new XMLHttpRequest();
    } else if (window.ActiveXObject) { 
        return new ActiveXObject("Msxml2.XMLHttp");
    }
    return null;
}

javascript Drag

Have you seen cool drag&drop features in some websites, with which you can dynamicly arrange web contents? If not, check out google personal or msn space.

It turns out not that difficult to implement your own drag and drop. Below is a very lightweight and customizable web Drag&Drop support using javascript and dhtml. Supports both IE and Firefox.

<script type="text/javascript">
  function getEvent(e) {
  return e ? e : window.event;
}

function moveElem(elem, left, top) {
  var style = elem.style;
  style.left = left;
  style.top = top;
}

function Drag(elem) {
  var self = this;
  this.elem = elem;

  elem.onmousedown = function(e) {
    e = getEvent(e);
    self.onBeginDrag(e.clientX, e.clientY);
    saveLast(e.clientX, e.clientY);
    document.onmousemove = onmousemove;
    document.onmouseup = onmouseup;
    return false;
  }

  function onmousemove(e) {
    e = getEvent(e);
    self.onDrag(e.clientX, e.clientY);
    saveLast(e.clientX, e.clientY);
    return false;
  }

  function onmouseup(e) {
    e = getEvent(e);
    document.onmousemove = null;
    document.onmouseup = null;
    self.onEndDrag(e.clientX, e.clientY);
    return false;
  }

  function saveLast(x, y) {
    self.x0 = x;
    self.y0 = y;
  }
}

Drag.prototype.move = function(dx, dy) {
  var style = this.elem.style;
  var x = parseInt(style.left);
  var y = parseInt(style.top);
  style.left = x + dx;
  style.top = y + dy;
}

Drag.prototype.moveTo = function(x, y) {
  moveElem(this.elem, x, y);
}

Drag.prototype.drag = function(x, y) {
  this.move(x - this.x0, y - this.y0);
}

Drag.prototype.onDrag = function(x, y) {
  this.drag(x, y);
}

Drag.prototype.onBeginDrag = function(x, y) {}
Drag.prototype.onEndDrag = function(x, y) {}
</script>


To make an element draggable, simply call "new Drag(elem)" for the element, e.g.,

<img id="dragimg" src="...">
<script type="text/javascript">
  new Drag(document.getElementById("dragimg"));
</script>